LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default File exists, but code doesn't find it?

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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot find file - code error keri Excel Programming 2 June 30th 07 03:21 PM
VBA code for tab exists MFINE Excel Programming 2 June 29th 07 11:26 PM
How to programmatically test whether VBA code exists in an Excel file Paul Martin Excel Programming 7 July 3rd 06 06:25 AM
Code To find and run an EXE file out side of the Excel A-Design Excel Programming 5 October 6th 04 01:06 PM
Cant get my code work. Find file or create it Poseilus Excel Programming 1 October 12th 03 03:42 PM


All times are GMT +1. The time now is 12:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"