Need advise on how to copy a file based on last modified date

samualgrowler

New Member
Joined
Jun 9, 2015
Messages
1
Hello all,

Background: I have several different invoices placed in five different folders , each week those invoices will be updated by our finance department, and saved under the same name.

The issue :The issue is all the files always saved under different extensions, for example,
file1_060920158686, next week the file will be updated to file1_061620158466, and those files are saved on a sharepoint site.

Questions :I found a code on this forum that allow me to copy the files to a shared folder, is there a way that will allow me to search the file by the last modified date, then copy the file by its last modified date, and place it in the shared folder?
How can I implement a code that will continuously loop until all the files from different network folders on that sharepoint site are all copied to my hard drive?

Here is the code I found on this forum.
Code:
Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
  "URLDownloadToFileA" ( _
  ByVal pCaller As Long, ByVal szURL As String, _
  ByVal szFileName As String, _
  ByVal dwReserved As Long, _
  ByVal lpfnCB As Long) As Long


Sub DownloadFileFromWeb()
Dim i As Integer

 Const strUrl As String = "http://teams/Dept/Shared Documents/Reports/Pivot_Source_Data/filename.csv"
 Dim strSavePath As String
 Dim returnValue As Long
 
 strSavePath = "C:\Reports\Pivot_Source_Data\xxxxxxxx.CSV"
 returnValue = URLDownloadToFile(0, strUrl, strSavePath, 0, 0)
 
End Sub


Thanks in advance
 
Last edited by a moderator:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello,

May be the following function to get the most recent ... can help ...
Code:
Function MostRecent(ByVal Folder As String, ByVal Identi As String) As String
Dim FSO As Object 'FileSystemObject
Dim f As Object 'File
Dim LastDate As Date
  
  Set FSO = CreateObject("Scripting.FileSystemObject")
  On Error GoTo ExitPoint
  For Each f In FSO.GetFolder(Folder).Files
    If InStr(1, f.Name, Identi, 1) Then
      If f.DateCreated > LastDate Then
        LastDate = f.DateCreated
        MostRecent = f.Name
      End If
    End If
  Next
ExitPoint:
End Function
 
Upvote 0

Forum statistics

Threads
1,196,052
Messages
6,013,115
Members
441,748
Latest member
MrBigglesworth

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