Share point vba

Excelexcel86

Board Regular
Joined
Feb 28, 2023
Messages
99
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi guys with the code below can this be modified where I can get only the most recent csv from different share point folders .

Sub openalllatestfiles()
Dim mypath As String
Dim myfile As String
Dim latestfile As String
Dim latestdate As Date
Dim wb As Workbook, ws As Worksheet '''''' new dims
Dim wsD As Worksheet ''''''''''' new dims
Dim rCell As Range, wsFiles As Worksheet
Dim land As Date

Set wsD = Sheets("Run All") '''''' Sheet to write values to (***Create this sheet***)
Set wsFiles = Sheets("Files") '''''' list of paths (column A) (***Create this sheet***)

For Each rCell In wsFiles.Range("A2:A" & wsFiles.Range("A" & Rows.Count).End(xlUp).Row).Cells
mypath = rCell.Value
If Right(mypath, 1) <> "\" Then mypath = mypath & "\"
myfile = Dir(mypath & "*.csv", vbNormal)
If Len(myfile) = 0 Then
Exit Sub
End If
Do While Len(myfile) > 0
land = Format(FileDateTime(mypath & myfile), "dd/mm/yyyy hh:mm:ss")
If land > latestdate Then
latestfile = myfile
latestdate = Format(land, "dd/mm/yyyy hh:mm:ss")
End If
myfile = Dir
Loop
latestdate = 0
Set wb = Workbooks.Open(mypath & latestfile) ' capture opened workbook
Set ws = wb.Sheets(1) ' capture sheet1 of opened workbook
ws.UsedRange.Offset(1).Copy ' copy the range from the opened workbook
wsD.Range("A" & wsD.Range("A" & Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues ' paste data into Run All sheet
Application.CutCopyMode = False
wb.Close False ' close the opned workbook without save
Next rCell
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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