Opening file, alternative paths

Hi,

A different user has a slightly different path to a spreadsheet as another

User 1
"x:\Morris Info\ME_Morris_Project\ME Downloads\"
User 2
"x:\SPM\Morris Info\ME_Morris_Project\ME Downloads"

So i am using "Workbooks.Open Filename:= _"

Is there a line of code to say, if path "x:\Morris Info\ME_Morris_Project\ME Downloads\" not found, then try path

"x:\SPM\Morris Info\ME_Morris_Project\ME Downloads"


Many thanks
Seamus2626Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

duncanb7Commented:
You need Dir() function on VBA to check the file path existing or not
before switching to other file path
Duncan
sub test()
Filename="example.xls"
localfile="x:\Morris Info\ME_Morris_Project\ME Downloads\"
localfile2="x:\SPM\ME_Morris_Project\ME Downloads\"
If Dir(localfile) <> "" Then
    MsgBox "File exists."
'Do your code here
 Workbooks.Open Filename:=localfile & "\"  & Filename
Else
    MsgBox "File doesn't exist."
'Do you cod here
Workbooks.Open Filename:= localfile2 & "\" & Filename

End If

End Sub

Open in new window

0
Seamus2626Author Commented:
Thanks Duncan,

When running the code, its is skipping to

Else
   
Workbooks.Open Filename:=localfile2 & "\" & Filename

Whereas localfile is available, and should be opening, it is skipping to localfile2 which is not available from my PC!

Thanks
0
duncanb7Commented:
Try this
Duncan
sub test()
Filename="example.xls"
localfile="x:\Morris Info\ME_Morris_Project\ME Downloads\"
localfile2="x:\SPM\ME_Morris_Project\ME Downloads\"
If Dir(localfile & "\" & Filename) <> "" Then
    MsgBox "File exists."
'Do your code here
 Workbooks.Open Filename:=localfile & "\"  & Filename
Else
    MsgBox "File doesn't exist."
'Do you cod here
Workbooks.Open Filename:= localfile2 & "\" & Filename

End If

End Sub

Open in new window

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

duncanb7Commented:
Ignore in last previous post, try this with directory check from vbDirectory at
http://www.techonthenet.com/excel/formulas/dir.php
sub test()
Filename="example.xls"
localfile="x:\Morris Info\ME_Morris_Project\ME Downloads\"
localfile2="x:\SPM\ME_Morris_Project\ME Downloads\"
If Dir(localfile ,vbDirectory) <> "" Then
    MsgBox "File exists."
'Do your code here
 Workbooks.Open Filename:=localfile & "\"  & Filename
Else
    MsgBox "File doesn't exist."
'Do you cod here
Workbooks.Open Filename:= localfile2 & "\" & Filename

End If

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seamus2626Author Commented:
Thanks Duncan!
0
duncanb7Commented:
Thanks for your points

Have a nice day

Duncan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.