Problem with storing date/time in a variable using VBA

J_T_Excel

New Member
Joined
Jan 14, 2011
Messages
15
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:

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.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Norie,

Thanks a million. I knew it had to be something like that. Should have been able to figure that out on my own. :oops:

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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