View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Alain-79 Alain-79 is offline
external usenet poster
 
Posts: 16
Default How to Connect a network Drive

Here is the answer I found...

At the time I need to to the getFolder on a path (pathToCheck) based on a
network drive (Z) that can be disconnected,
- I first recover the remotePath from the registry key...
Dim oShell As Object: dim remPath$
Set oShell = CreateObject("WScript.Shell")
remPath= oShell.RegRead("HKEY_CURRENT_USER\Network\Z\Remote Path")
- second I map it again - this will re-connect in case not
Dim objWSNet As Object, strDrive As String, strUNCPath As String
Set objWSNet = CreateObject("WScript.Network")
objWSNet.MapNetworkDrive Z:, remPath
- then I can do my getFolder which will fail only if I am not connected to
the network...
fld = fso.GetFolder(pathToCheck)


Thanks to the ones who answered...
Regards
Alain

"Alain-79" wrote:

Using fso, I need to be able to make a getFolder on several possible path
including Network Drives... but when one of them is not connected I get an
error...

It's rather simple to open the explorer and to click on this network drive
in order toget it connected... but how can I automate this through vba code...

In other words: How can I through vba connect an existing network drive and
this even if I have just the logical path such as Z:\Folder

Using <<Net Use would imply I have kept the network path such as
\\server\...\shared folder or at least that I am capable of recovering it...

Thanks for any potential help...
Regards
Alain