You are here:

Excel/Scope FTP folder for modified date/time


Hello Damon,

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.


Hi Dave,

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
End Function

Sub Check4Changes()

  '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
         GoTo ReSchedule
        ElseIf .Value < LastMod Then
         .Value = LastMod
         MsgBox FolderNames(Findex) & " folder updated.", vbInformation, "Check4Changes"
        End If
     End With
  Next Findex
     '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"
End Sub

Sub CancelChecking()
  Application.OnTime NextTime, "Check4Changes", Schedule:=False
  Application.StatusBar = False
End Sub

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()
End Sub

I hope you find this helpful.


About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Damon Ostrander


I have extensive experience with VBA programming in Excel 5 through Excel 2013. As a former aerospace engineer with a large aerospace corporation and consultant in a small defense technology services company, I have developed a wide range of applications in VBA, including simulations involving mixed-language programming, satellite orbit mechanics, graphics and animation, and real-time applications. I am interested in moderate to hard VBA-related questions only.


I have developed and taught several courses in Excel VBA programming and also VBA programming in Office 97, 2000, and 2007. I have developed a number of large technical applications in Excel VBA for use within the aerospace industry.

B.S. in Electrical Engineering and Computer Science, University of California, Berkeley.

©2016 All rights reserved.