![]() |
check for valid file
I'm using a routine to run thru a list of files and open them to modif
certain things. here is the chunk of code that open uo the file and activates it Workbooks.Open WindowName Windows(WindowName + ".xls").Activate how can check to see if a file exist before I attempt to open it? the minute it hist the first line,if the file does not exist..i crashes. I need to be able to check first to be able to handle non existin files. thanks Pab -- Message posted from http://www.ExcelForum.com |
check for valid file
Use DIR command
Several examples =============== sPath$ = ThisWorkbook.Path & "\Data" sFname$ = "Data.xls" sFile$ = sPath & "\" & sFname If Dir(sPath, vbDirectory) = "" Then MkDir (sPath) End If =============== If Dir(sFile) = "" Then Exit Sub End If =================== sDir = Dir(sPath & "\*.*") Do If sDir = "" Then Exit Do End If more code here sDir = Dir ' gets the next file Loo -- Message posted from http://www.ExcelForum.com |
check for valid file
John Walkenbach has some good functions at:
http://j-walk.com/ss/excel/tips/tip54.htm#func1 hth, Doug "pabs " wrote in message ... I'm using a routine to run thru a list of files and open them to modify certain things. here is the chunk of code that open uo the file and activates it Workbooks.Open WindowName Windows(WindowName + ".xls").Activate how can check to see if a file exist before I attempt to open it? the minute it hist the first line,if the file does not exist..it crashes. I need to be able to check first to be able to handle non existing files. thanks Pabs --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 12:14 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com