I've written some code that I would like to conditionally execute on certain files that have been updated since the last time the code was executed. In order to accomplish this, I've written the NOW() formula to a cell (K5) in more worksheet at the end of the code so that each time it executes the date and time of the execution is recorded. I read that date and time into a variable at the beginning of my code so that it can be compared to the FileDateTime of all the files in the directories in which I'm working. Here's what the applicable portion of my code looks like currently:
The problem is that the variable "LastUpdate" is reading the contents of K5 in a different format than I'm intending. For example, "K5" currently reads 4/15/2011 10:13 AM but when that cells contents are written to the variable LastUpdate it is stored as 40648. I'm pretty new to this so I'm sure it's something stupid that I'm doing and I'm sure my code is pretty terrible in general but any insight you guys can provide would be much appreciated. Thanks.
Code:
Dim strFileName As String, strPath As String, wbkOld As Workbook, LastUpdate As Long, x As Long, NameLength As Long, OnlyName As String
Application.EnableEvents = False 'disable the BeforeSave event so default dialog boxes do not appear when files are saved
Application.DisplayAlerts = False 'disable alert for file save procedure
strPath1 = "Q:\Engineering\Microvellum\Frameless Library Imperial\Library\EDI Counter Tops\" 'set default directory for accessing .cutx files
strPath2 = "Q:\Engineering\Rev. Comparison Data\Library\EDI Counter Tops\" 'set default directory for copying .cutx files and saving .xls files
strFileName = Dir(strPath1 & "*.cutx") 'set file name = to default directory defined above and any files with .cutx extension
LastUpdate = Sheets("Comparison").Range("K5").Value 'Search for last update date for library items
x = 0
Do While Len(strFileName) > 0 'loop while file names exist
If FileDateTime(strPath1 & strFileName) > LastUpdate Then 'if the saved date of a file in the directory is more recent that the last library update date
The problem is that the variable "LastUpdate" is reading the contents of K5 in a different format than I'm intending. For example, "K5" currently reads 4/15/2011 10:13 AM but when that cells contents are written to the variable LastUpdate it is stored as 40648. I'm pretty new to this so I'm sure it's something stupid that I'm doing and I'm sure my code is pretty terrible in general but any insight you guys can provide would be much appreciated. Thanks.