![]() |
Txt file properties
XL2003 on WinXP
I'm piecing together VBA code to identify if a target file exists, and if so, to open it and parse it into memory and further calculations (file is under 65K lines). The text file is created within MS Outlook using a macro to dump an email (report from a mainframe) to the text file. When my XL macro is run, I want to check the last saved date of the txt file; if it was the same day (today) then the report should run without interruption. If the txt file was saved prior to the same day, I plan to throw an alert and allow the user to decide whether to continue (txt file is recent enough) or cancel (to go back and find more recent data). I can handle the logic of the date comparison and the alert box; but I'm struggling with how to identify the last saved date of the text file. I've appended the relevant lines of code below; what should I add as my 5th line to pull the last saved date of this file, if it exists? Many thanks, Keith Application.StatusBar = "Loading Backlog Data File" Set mywrksht = MySheetArray(WhichFile) LongFN = tPath & MyFileNameArray(WhichFile) & tSuffix If Dir(LongFN) = MyFileNameArray(WhichFile) & tSuffix Then 'tells me if file exists (?) 'something like: TxtDate = Dir(LongFN).attributes.lastsaveddate '...code continues here |
Txt file properties
I think that you may need to use the filesystemobject for this.
GB "Keith R" wrote in message ... XL2003 on WinXP I'm piecing together VBA code to identify if a target file exists, and if so, to open it and parse it into memory and further calculations (file is under 65K lines). The text file is created within MS Outlook using a macro to dump an email (report from a mainframe) to the text file. When my XL macro is run, I want to check the last saved date of the txt file; if it was the same day (today) then the report should run without interruption. If the txt file was saved prior to the same day, I plan to throw an alert and allow the user to decide whether to continue (txt file is recent enough) or cancel (to go back and find more recent data). I can handle the logic of the date comparison and the alert box; but I'm struggling with how to identify the last saved date of the text file. I've appended the relevant lines of code below; what should I add as my 5th line to pull the last saved date of this file, if it exists? Many thanks, Keith Application.StatusBar = "Loading Backlog Data File" Set mywrksht = MySheetArray(WhichFile) LongFN = tPath & MyFileNameArray(WhichFile) & tSuffix If Dir(LongFN) = MyFileNameArray(WhichFile) & tSuffix Then 'tells me if file exists (?) 'something like: TxtDate = Dir(LongFN).attributes.lastsaveddate '...code continues here |
Txt file properties
See if you can work with this
Dim oFS As Object Dim oFile As Object Set oFS = CreateObject("Scripting.FilesystemObject") On Error Resume Next Set oFile = oFS.getfile("C:\test\SP Test.xls") On Error GoTo 0 If Not oFile Is Nothing Then MsgBox CDate(oFile.DateLastModified) End If -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Keith R" wrote in message ... XL2003 on WinXP I'm piecing together VBA code to identify if a target file exists, and if so, to open it and parse it into memory and further calculations (file is under 65K lines). The text file is created within MS Outlook using a macro to dump an email (report from a mainframe) to the text file. When my XL macro is run, I want to check the last saved date of the txt file; if it was the same day (today) then the report should run without interruption. If the txt file was saved prior to the same day, I plan to throw an alert and allow the user to decide whether to continue (txt file is recent enough) or cancel (to go back and find more recent data). I can handle the logic of the date comparison and the alert box; but I'm struggling with how to identify the last saved date of the text file. I've appended the relevant lines of code below; what should I add as my 5th line to pull the last saved date of this file, if it exists? Many thanks, Keith Application.StatusBar = "Loading Backlog Data File" Set mywrksht = MySheetArray(WhichFile) LongFN = tPath & MyFileNameArray(WhichFile) & tSuffix If Dir(LongFN) = MyFileNameArray(WhichFile) & tSuffix Then 'tells me if file exists (?) 'something like: TxtDate = Dir(LongFN).attributes.lastsaveddate '...code continues here |
Txt file properties
Awesome, that worked perfectly. Thank you for the assistance!
Keith "Bob Phillips" wrote in message ... See if you can work with this Dim oFS As Object Dim oFile As Object Set oFS = CreateObject("Scripting.FilesystemObject") On Error Resume Next Set oFile = oFS.getfile("C:\test\SP Test.xls") On Error GoTo 0 If Not oFile Is Nothing Then MsgBox CDate(oFile.DateLastModified) End If -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Keith R" wrote in message ... XL2003 on WinXP I'm piecing together VBA code to identify if a target file exists, and if so, to open it and parse it into memory and further calculations (file is under 65K lines). The text file is created within MS Outlook using a macro to dump an email (report from a mainframe) to the text file. When my XL macro is run, I want to check the last saved date of the txt file; if it was the same day (today) then the report should run without interruption. If the txt file was saved prior to the same day, I plan to throw an alert and allow the user to decide whether to continue (txt file is recent enough) or cancel (to go back and find more recent data). I can handle the logic of the date comparison and the alert box; but I'm struggling with how to identify the last saved date of the text file. I've appended the relevant lines of code below; what should I add as my 5th line to pull the last saved date of this file, if it exists? Many thanks, Keith Application.StatusBar = "Loading Backlog Data File" Set mywrksht = MySheetArray(WhichFile) LongFN = tPath & MyFileNameArray(WhichFile) & tSuffix If Dir(LongFN) = MyFileNameArray(WhichFile) & tSuffix Then 'tells me if file exists (?) 'something like: TxtDate = Dir(LongFN).attributes.lastsaveddate '...code continues here |
All times are GMT +1. The time now is 07:48 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com