Excel/Scope FTP folder for modified date/time
I have seen answers from you for slightly different versions of this but I am still not able to apply this to what I need.
Basically I have an FTP site containing 5 folders. Various people from across the continent will upload to these directories and I must be fairly quick in grabbing the files uploaded and processing them.
All I am looking to do is to create a routine that will check the modified dates on the 5 folders (this may increase to more) and pop up a msg box stating that there was a new file uploaded.
I am currently using Excel 2007 within Windows7.
I consider myself a "copy and paste" VBA programmer as I am still learning many of the features of VBA.
Thank you for your time.
I am assuming that your FTP site is logged on your computer as a network drive. If this is the case then this code should work for you. If not let me know and I'll see if I can modify the code for a web-oriented approach.
This is a slightly modified version of what I posted in the past, but it assumes that the 5 folders are located in the same parent folder. It checks the folders once per minute, but that can be changed in the code by editing the arguments of the TimeSerial function.
Here's the code:
Dim NextTime As Date
Function LastModTime(FolderSpec As String) As Date
'Returns the date-time the file specified by FileSpec (path string) was last modified
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.Getfolder(FolderSpec)
LastModTime = f.DateLastModified
'Monitors group of folders and notifys when a folder changes
'Checks the folders in FolderPaths array for changes every 60 seconds
'If folder (contents) has changed, pops up a message box. Stores the
'last modified times of folders in column M of Sheet1
Dim FolderNames As Variant 'array of folder names to monitor
Dim ParentFolderPath As String 'path to parent folder of monitored folders
Dim FolderPath As String
Dim LastMod As Date 'date/time a folder was last modified
Dim Findex As Integer 'the index of the folder in the FolderNames array
ParentFolderPath = "C:\Documents and Settings\My Documents\Temp\"
FolderNames = Array("Pictures", "Test")
On Error GoTo ReSchedule
'Check all folders in FolderPaths for updates
For Findex = 0 To UBound(FolderNames)
FolderPath = ParentFolderPath & FolderNames(Findex)
LastMod = LastModTime(FolderPath)
With Worksheets("Sheet1").Cells(Findex + 1, "M")
If IsEmpty(.Value) Then
.Value = LastMod
ElseIf .Value < LastMod Then
.Value = LastMod
MsgBox FolderNames(Findex) & " folder updated.", vbInformation, "Check4Changes"
'Reschedule this same routine to run in one minute.
NextTime = Now + TimeSerial(0, 1, 0)
Application.StatusBar = "Next check at " & NextTime
Application.OnTime NextTime, "Check4Changes"
Application.OnTime NextTime, "Check4Changes", Schedule:=False
Application.StatusBar = False
In this code you must enter the array of names of the folders you want to monitor in the FolderNames statement as in the example
FolderNames = Array("Pictures", "Test") (which shows two folders, Pictures and Test).
You must also enter the network drive path where the folders are located as a string in the ParentFolderPath statement as in the example
ParentFolderPath = "C:\Documents and Settings\My Documents\Temp\".
Start this code by running the macro Check4Changes. If you want Check4Changes to start automatically when you open the workbook add the following code to the ThisWorkbook code module in your workbook.
Private Sub Workbook_Open()
I hope you find this helpful.