简体   繁体   English

打开 SharePoint 文档库上文件夹中的最新工作簿

[英]Open most recent workbook in a folder on SharePoint document library

I would like to open the most recent workbook in SharePoint document library.我想打开 SharePoint 文档库中的最新工作簿。 The file is saved as an archive that I need to access to pull information from.该文件保存为我需要访问以从中提取信息的存档。

I have tried a bit of VBA script that allowed me to access the file through CAFs but since all my folders have been moved online to 365 I need a new way to access the most recent archive workbook in the folder.我尝试了一些 VBA 脚本,它允许我通过 CAF 访问文件,但由于我的所有文件夹都已在线移动到 365,我需要一种新方法来访问文件夹中最新的存档工作簿。

'Force the explicit delcaration of variables
Option Explicit

Sub OpenLatestFile()

     'Declare the variables
     Dim MyPath  As String
     Dim MyFile  As String
     Dim LatestFile  As String
     Dim LatestDate  As Date
     Dim LMD  As Date

     'Specify the path to the folder
     MyPath = "file location on sharepoint"

     'Make sure that the path ends in a backslash
     If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"

     'Get the first Excel file from the folder
     MyFile = Dir(MyPath & "*.xlsm")

     'If no files were found, exit the sub
     If Len(MyFile) = 0 Then
         MsgBox "No files were found...", vbExclamation
         Exit Sub
     End If

     'Loop through each Excel file in the folder
     Do While Len(MyFile) > 0

         'Assign the date/time of the current file to a variable
         LMD = FileDateTime(MyPath & MyFile)

         'If the date/time of the current file is greater than the latest
         'recorded date, assign its filename and date/time to variables
         If LMD > LatestDate Then
             LatestFile = MyFile
             LatestDate = LMD
         End If

         'Get the next Excel file from the folder
         MyFile = Dir

     Loop

     'Open the latest file
     Workbooks.Open MyPath & LatestFile

You should still be able to use Dir:您应该仍然可以使用 Dir:

Const PATH As String = "\\companyHere.sharepoint.com\Departments\Blah\Stuff\"

Dim f

f = Dir(PATH & "*.xlsx")

Debug.Print f
Debug.Print FileDateTime(PATH & f)

works for me.为我工作。

Solved this problem.解决了这个问题。 I had to use the URL path.我不得不使用 URL 路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM