tchristie33
asked on
Check path before opening workbook in excel vb
I have the following code below which opens a workbook in excel, however, i was wondering if there was a way to check if the path is valid before trying to open it up and getting an error. I don't want to use an err.number solution. I also put a pic of the error that shows when it tries to open a workbook that doesn't exist.
Workbooks.Open D.[B2].Text, never
Delete1.pdf
Workbooks.Open D.[B2].Text, never
Delete1.pdf
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
whay you don't want to use an err.number solution ?
FileSystemObject:
http://msdn.microsoft.com/en-us/library/z9ty6h50(VS.85).aspx
http://msdn.microsoft.com/en-us/library/z9ty6h50(VS.85).aspx
ASKER
i just don't like to code that way i guess, figure there has to be a better way to do it.
If Dir$("C:\MyPath\MyFile.Xls ") <> "" then
Set Wbk = WorkBooks.Open("C:\MyPath\ MyFile.Xls ")
Set Wbk = WorkBooks.Open("C:\MyPath\
The code i sent will not work in VBScript. Please see
http://msdn.microsoft.com/en-us/library/z9ty6h50(VS.85).aspx
for how to use FileSystemObject in VBS.
(in vbs you gotta use CreateObject() )
http://msdn.microsoft.com/en-us/library/z9ty6h50(VS.85).aspx
for how to use FileSystemObject in VBS.
(in vbs you gotta use CreateObject() )