Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to Connect a network Drive
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to Connect a network Drive
Hi Alain
---If you are looking to Get the folder object you dont need to map that as a drive..Instead you can directly mention the UNC Path as below Dim fso As Object, objFolder As Object Set fso = CreateObject("Scripting.FileSystemObject") Set objFolder = fso.GetFolder("\\server\share folder") MsgBox objFolder.Name ---If you are looking to map this folder as a network drive then try the below Dim objWSNet As Object, strDrive As String, strUNCPath As String Set objWSNet = CreateObject("WScript.Network") strDrive = "Z:" strUNCPath = "\\server\share folder" objWSNet.MapNetworkDrive strDrive, strUNCPath -- Jacob "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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to Connect a network Drive
A Z:\file you should be able to access like any drive if you have the correct priviledges. If you can open the file useing a window explorer then you should be able to just use getfile(). I don't know what the problem you are having but I would first try your code on a file in the d: drive just to make sure the code is working properly. Some network files may no have local privildedges for you to access the file dirrectly. they may have the same prilideges as a Web file. because some files may be capable of being accessed through the internet. You may need to use FTP (File Transfer Protocol) to access the files which is used get get files and directories over the Internet. It would help to know what your intentions are going to be to get you to use the corect protocol. the correct methos may be differet depending if you were going to open the file/ Get the files size, get file priviledges, etc. -- joel ------------------------------------------------------------------------ joel's Profile: 229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=161641 Microsoft Office Help |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to Connect a network Drive
I know I can do that but the problem is that up to now I have not kept the
absolute path starting with \\server\... I have just made a list of potential path that could be used but those path are just kept whith their Network Drive letter, not with their full path... And then when then Network Drive my users will like to use is not connected I have no way up to now to provoce the re-connection, not no way to recover the full path... except if this last one would be available somewhere like in a Registry key... The unique solution I can imagine at the moment is to keep a memo of the full path in // to the logical path at the time it is entered in my list... Then I will be able to reconnect it using net use or any other possible function for that task... Thanks for your input Alain PS regarding your code proposal thanks to remember I cannot access the full path mine is a follow set fso = CreateObject("Scripting.FileSystemObject") set objFolder = GetFolder(Z:\SharedFolder) Z is here a map drive I created through Explorer the <<set objFolder code line produces an error if the Network Drive is not connected which is systematically the case just after login... If you go to the explorer and click inside the Z drive = it open it Then the same code lines will not produce any errors... |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to Connect a network Drive
Hi Joel, my code works in many circumstances... and even the part with which
I am facing problems do not produce any errors as soon as the Network drive is "Connected" My current problem would rather be to be said as follow 1 - I have saved somewhere a path based on a Network Drive - let say Z:\Folder 2 - I have not savec the full path starting with \\server\...\Folder 3 - After a while or after a logoff - logon, the Network Drive is not connected any more - you can see that in the explorer when looking to "My Computer"... all Network drive present either the status "Disconnected Network Drive" or "Network Drive" only for all connected ones... 4 - if at that moment I run those code lines I get an error - set fso = CreatObject("Scripting.FileSystemObject") - Set folder = fso.GetFolder(Z:\Folder) I know that I could have it working if I could access the full path but do not know how to recover it on a Disconnected Network Drive ? in a registry key ? Thanks for your help Alain |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to Connect a network Drive
There is always a possibility that the user change the drive mapping to
something else. So it is always better to use the UNC path either stored in an .ini file or if in VBA stored in a dedicated sheet/cell so that you dont need to be 'drive letter' dependent. -- Jacob "Alain-79" wrote: I know I can do that but the problem is that up to now I have not kept the absolute path starting with \\server\... I have just made a list of potential path that could be used but those path are just kept whith their Network Drive letter, not with their full path... And then when then Network Drive my users will like to use is not connected I have no way up to now to provoce the re-connection, not no way to recover the full path... except if this last one would be available somewhere like in a Registry key... The unique solution I can imagine at the moment is to keep a memo of the full path in // to the logical path at the time it is entered in my list... Then I will be able to reconnect it using net use or any other possible function for that task... Thanks for your input Alain PS regarding your code proposal thanks to remember I cannot access the full path mine is a follow set fso = CreateObject("Scripting.FileSystemObject") set objFolder = GetFolder(Z:\SharedFolder) Z is here a map drive I created through Explorer the <<set objFolder code line produces an error if the Network Drive is not connected which is systematically the case just after login... If you go to the explorer and click inside the Z drive = it open it Then the same code lines will not produce any errors... |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to Connect a network Drive
yes I know that too but on a daily basis they are
1 - not changing such things so often 2 - used to work with the Network Drive letter rather than with the absolute path they even do not know at all This is what I consider I should continue to present them what they know the most... Thanks once more to you Regards Alain "Jacob Skaria" wrote: There is always a possibility that the user change the drive mapping to something else. So it is always better to use the UNC path either stored in an .ini file or if in VBA stored in a dedicated sheet/cell so that you dont need to be 'drive letter' dependent. -- Jacob "Alain-79" wrote: I know I can do that but the problem is that up to now I have not kept the absolute path starting with \\server\... I have just made a list of potential path that could be used but those path are just kept whith their Network Drive letter, not with their full path... And then when then Network Drive my users will like to use is not connected I have no way up to now to provoce the re-connection, not no way to recover the full path... except if this last one would be available somewhere like in a Registry key... The unique solution I can imagine at the moment is to keep a memo of the full path in // to the logical path at the time it is entered in my list... Then I will be able to reconnect it using net use or any other possible function for that task... Thanks for your input Alain PS regarding your code proposal thanks to remember I cannot access the full path mine is a follow set fso = CreateObject("Scripting.FileSystemObject") set objFolder = GetFolder(Z:\SharedFolder) Z is here a map drive I created through Explorer the <<set objFolder code line produces an error if the Network Drive is not connected which is systematically the case just after login... If you go to the explorer and click inside the Z drive = it open it Then the same code lines will not produce any errors... |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Network drive | Excel Worksheet Functions | |||
map network drive | Excel Programming | |||
Using An Add-in On A Network Drive | Excel Programming | |||
Link workbooks-C drive to network drive | Excel Worksheet Functions | |||
Userform Local Drive & Network drive question | Excel Programming |