Help please! Open file dialog to network path only if available

farlice

New Member
Joined
Jun 27, 2011
Messages
2
Hi all,

I am very new to macros and VBA in excel and am having difficulty with one particular thing. I have managed to get the open file dialog to point to a particular folder on a network drive (Q). What I want is for it to point there if the user is logged on, i.e. Q is available, but if not goto "C:\Documents and Settings".

I have looked all over various message boards for a solution and have tried to cobble something together, but have failed completely.

My original code was:

ChDrive "Q"
ChDir "Q:\Link Files\Housing\PR"

This works fine, but obviously produces an error if not logged into the network. So I tried:

With drive
On Error GoTo Cdrive
ChDrive "Q"
ChDir "Q:\Link Files\Housing\PR"
Cdrive:
ChDrive "C"
ChDir "C:\Documents and Settings"
End With

I know this probably looks ridiculous to people who know about VBA, but I thought I would give it a go - have tried a number of variations to no avail.

Any help appreciated.

Thanks
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Code:
If Dir("Q:\Link Files\Housing\PR") <> vbNullString Then
    ' Network drive is available
End If
 
Upvote 0
Hi Sektor, thanks for very swift reply - I can see what your code does, but don't know how to fit it with my code (or if I need to make new code) in order for this to work.

I tried putting it in as follows:

If Dir("Q:\Link Files\Housing\PR") <> vbNullString Then
' Network drive is available
ChDrive "Q"
ChDir "Q:\Link Files\Housing\PR"
End If

But this returns the last folder viewed (Q is available to me at the moment, so presumably it should go there?)

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,696
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top