|
Subject:
|
Fileexists function
|
|
Posted By:
|
davespearce
|
Post Date:
|
1/11/2007 3:07:03 AM
|
Hi,
I can't get this piece of code to work using the sub(filexists) funtion taken from the Excel VBA 2002 book. No matter whether the file exists or not the code always executes the else statement rather than the next statement. Every other part of the code works fine.
Any help greatly appreciated as it's been driving me mad for ages. I'm sure it's something simple.
Thanks Dave
checkiffileisopen: stfullname = pathname & "\" & stFileName & ".xls" stFileName = GetFileName(stfullname) If IsWorkbookOpen(stFileName) Then Set Wkb = Workbooks(stFileName) Wkb.Activate Else ChDir pathname If FileExists(stFileName) = True Then Set Wkb = Workbooks.Open(Filename:=stfullname) Else GoTo dontprocess:
End If
End If
|
|
Reply By:
|
Shasur
|
Reply Date:
|
1/11/2007 3:24:01 AM
|
You can also use the simple Dir function
fFile = Dir$(stfullname, vbNormal) IF len(fFile) <> 0
' open the file
Else ' file does not exist
End if
Cheers Shasur
http://www.vbadud.blogspot.com
|