K
ker_01
I have some code that looks for a file; if it doesn't find it I need to exit
my sub because the rest of the sub clears my worksheet and imports new data
from the file. If the code runs without the file present, it clears my sheet
but doesn't have anything to import- which messes up a lot of subsequent
stuff.
Here is the code snippet; the problem is that I've manually placed the file
in the correct directory, but this code still doesn't find it, so it hits
the exit sub.
Any ideas what I'm doing wrong?
Thanks!!
Keith
Dim oFS As Object
Dim oFile As Object
Set oFS = CreateObject("Scripting.FilesystemObject")
On Error Resume Next
Set oFile = oFS.getfile(DataFileLocation)
On Error GoTo TTINT1NoFile:
If Not oFile Is Nothing Then 'e.g. if file is something- so this part
should execute but doesn't
'get date of file
DateTTINT1Modified = CDate(oFile.DateLastModified)
TTINT1OldDate = GetProperty("TTINT1Date", PropertyLocationCustom)
'if file is not new then alert user and don't bother to re-load file
If Not (DateTTINT1Modified > TTINT1OldDate) Then
MsgBox TTINT1 & " has not been modified since last data load;
file will not be reloaded until next updated file is available", , "Data
already loaded"
Exit Sub
End If
Else 'instead, it goes here and exits the sub
Exit Sub
End If
On Error GoTo 0
my sub because the rest of the sub clears my worksheet and imports new data
from the file. If the code runs without the file present, it clears my sheet
but doesn't have anything to import- which messes up a lot of subsequent
stuff.
Here is the code snippet; the problem is that I've manually placed the file
in the correct directory, but this code still doesn't find it, so it hits
the exit sub.
Any ideas what I'm doing wrong?
Thanks!!
Keith
Dim oFS As Object
Dim oFile As Object
Set oFS = CreateObject("Scripting.FilesystemObject")
On Error Resume Next
Set oFile = oFS.getfile(DataFileLocation)
On Error GoTo TTINT1NoFile:
If Not oFile Is Nothing Then 'e.g. if file is something- so this part
should execute but doesn't
'get date of file
DateTTINT1Modified = CDate(oFile.DateLastModified)
TTINT1OldDate = GetProperty("TTINT1Date", PropertyLocationCustom)
'if file is not new then alert user and don't bother to re-load file
If Not (DateTTINT1Modified > TTINT1OldDate) Then
MsgBox TTINT1 & " has not been modified since last data load;
file will not be reloaded until next updated file is available", , "Data
already loaded"
Exit Sub
End If
Else 'instead, it goes here and exits the sub
Exit Sub
End If
On Error GoTo 0