Txt file properties

K

Keith R

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
 
B

Bob Phillips

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top