Link to home
Start Free TrialLog in
Avatar of tchristie33
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
ASKER CERTIFIED SOLUTION
Avatar of davidsperling
davidsperling

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
whay you don't want to use an err.number solution ?
Avatar of davidsperling
davidsperling

Avatar of tchristie33

ASKER

i just don't like to code that way i guess, figure there has to be a better way to do it.
Avatar of GrahamSkan
If Dir$("C:\MyPath\MyFile.Xls") <> "" then
   Set Wbk = WorkBooks.Open("C:\MyPath\MyFile.Xls")
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() )