Attempting to find last file saved on sharepoint

yirrlaar

New Member
Joined
Jul 25, 2011
Messages
18
So I have used this code before to look at files when they were last saved locally, however when I attempt to use the same methodology when looking at a sharepoint website, I get an error at
Code:
Filename = Dir(DefPath & "*" & Format(CurDate, "Mmmm") & "*.xls*, vbNormal)
and yes, the file is on the sharepoint web folder.

What am I missing?? Please help!!
Code:
Sub Find_Last_Updated_Sharepoint_file()
    Application.DisplayAlerts = False
    Dim Cur_Date As Date
    Dim Fname, DefPath As Variant
    Dim Filename As String
    
    CurDate = Workbooks("Testing.xlsm").Sheets("Sheet1").Range("B2")
    DefPath = "http://sharepoint.website/"& Format(CurDate, "Mmmm") & "%20" & Format(CurDate, "yyyy") & "/"
    Filename = Dir(DefPath & "*" & Format(CurDate, "Mmmm") & "*.xls*", vbNormal)
       
    Do While Filename <> ""
        If FileDateTime(DefPath & Filename) > dtLast Then
            dtLast = FileDateTime(DefPath & Filename)
            latestFile = DefPath & Filename
        End If
        Filename = Dir
    Loop
    Filename = Dir$(latestFile)
    Fname = DefPath & Filename
    
    If BookOpen(Filename) = False Then Workbooks.Open Filename:=Fname
    
    Application.DisplayAlerts = True
End Sub

Thanks in advance!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Problem SOLVED

Code:
Sub Find_Last_Updated_Sharepoint_file()
    Application.DisplayAlerts = False
    Dim Cur_Date As Date
    Dim Fname, DefPath As Variant
    Dim Filename As String
    
    CurDate = Workbooks("Testing.xlsm").Sheets("Sheet1").Range("B2")
'remove the "http:" from in front of the share point location to be able to cycle & open last workbook saved
    DefPath = "//sharepoint.website/"& Format(CurDate, "Mmmm") & "%20" & Format(CurDate, "yyyy") & "/"
    Filename = Dir(DefPath & "*" & Format(CurDate, "Mmmm") & "*.xls*", vbNormal)
       
    Do While Filename <> ""
        If FileDateTime(DefPath & Filename) > dtLast Then
            dtLast = FileDateTime(DefPath & Filename)
            latestFile = DefPath & Filename
        End If
        Filename = Dir
    Loop
    Filename = Dir$(latestFile)
    Fname = DefPath & Filename
    
    If BookOpen(Filename) = False Then Workbooks.Open Filename:=Fname
    
    Application.DisplayAlerts = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top