Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
using a macro to map a shared drive
Gents,
Is there a way to write a macro that when its run it will map a network drive. it needs to also include the reconnect at logon. This will save me having to tell people how to do it all the time regards Popeye |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
using a macro to map a shared drive
Always using the same drive letter and the same path???
Option Explicit Sub testme() Dim res As Variant res = TryToMapIt("G", "\\myserver\mypath") If res = True Then MsgBox "it worked" Else MsgBox res End If End Sub Function TryToMapIt(myDrive, NewPath) As Variant Dim FixedIt As Variant Dim FSO As Object Dim WSHNetwork As Object Set WSHNetwork = CreateObject("WScript.Network") Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.driveexists(myDrive) Then WSHNetwork.RemoveNetworkDrive myDrive, True, True End If FixedIt = False On Error Resume Next WSHNetwork.MapNetworkDrive myDrive, NewPath, True If Err.Number = 0 Then FixedIt = True Else If Err.Number < 0 Then FixedIt = Err.Description End If Err.Clear End If TryToMapIt = FixedIt End Function Popeye the powerman wrote: Gents, Is there a way to write a macro that when its run it will map a network drive. it needs to also include the reconnect at logon. This will save me having to tell people how to do it all the time regards Popeye -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
using a macro to map a shared drive
Dave,
I assume I replace ("G", "\\myserver\mypath") with my drive letter and server if thats the case it doesn't appear to work and comes back with "the specified device name is invalid". Is there another bit of the code I should be altering. Also yes it will always be the same letter "Dave Peterson" wrote: Always using the same drive letter and the same path??? Option Explicit Sub testme() Dim res As Variant res = TryToMapIt("G", "\\myserver\mypath") If res = True Then MsgBox "it worked" Else MsgBox res End If End Sub Function TryToMapIt(myDrive, NewPath) As Variant Dim FixedIt As Variant Dim FSO As Object Dim WSHNetwork As Object Set WSHNetwork = CreateObject("WScript.Network") Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.driveexists(myDrive) Then WSHNetwork.RemoveNetworkDrive myDrive, True, True End If FixedIt = False On Error Resume Next WSHNetwork.MapNetworkDrive myDrive, NewPath, True If Err.Number = 0 Then FixedIt = True Else If Err.Number < 0 Then FixedIt = Err.Description End If Err.Clear End If TryToMapIt = FixedIt End Function Popeye the powerman wrote: Gents, Is there a way to write a macro that when its run it will map a network drive. it needs to also include the reconnect at logon. This will save me having to tell people how to do it all the time regards Popeye -- Dave Peterson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
using a macro to map a shared drive
Try connecting (and disconnecting manually).
Then share the details of what worked manually. Then share how you changed the code. The code worked for me in the past -- but I don't have access to a network, so I won't be able to do any real testing. But if you post what you tried, maybe some reader will see a typo... Popeye the powerman wrote: Dave, I assume I replace ("G", "\\myserver\mypath") with my drive letter and server if thats the case it doesn't appear to work and comes back with "the specified device name is invalid". Is there another bit of the code I should be altering. Also yes it will always be the same letter "Dave Peterson" wrote: Always using the same drive letter and the same path??? Option Explicit Sub testme() Dim res As Variant res = TryToMapIt("G", "\\myserver\mypath") If res = True Then MsgBox "it worked" Else MsgBox res End If End Sub Function TryToMapIt(myDrive, NewPath) As Variant Dim FixedIt As Variant Dim FSO As Object Dim WSHNetwork As Object Set WSHNetwork = CreateObject("WScript.Network") Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.driveexists(myDrive) Then WSHNetwork.RemoveNetworkDrive myDrive, True, True End If FixedIt = False On Error Resume Next WSHNetwork.MapNetworkDrive myDrive, NewPath, True If Err.Number = 0 Then FixedIt = True Else If Err.Number < 0 Then FixedIt = Err.Description End If Err.Clear End If TryToMapIt = FixedIt End Function Popeye the powerman wrote: Gents, Is there a way to write a macro that when its run it will map a network drive. it needs to also include the reconnect at logon. This will save me having to tell people how to do it all the time regards Popeye -- Dave Peterson -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
using a macro to map a shared drive
Dave,
Found this on the scripting forum & does what I wanted Share = "\\Drive\Group" Set objNetwork = CreateObject("Wscript.Network") objNetwork.MapNetworkDrive "Z:", Share Thanks for your assistance Popeye "Dave Peterson" wrote: Try connecting (and disconnecting manually). Then share the details of what worked manually. Then share how you changed the code. The code worked for me in the past -- but I don't have access to a network, so I won't be able to do any real testing. But if you post what you tried, maybe some reader will see a typo... Popeye the powerman wrote: Dave, I assume I replace ("G", "\\myserver\mypath") with my drive letter and server if thats the case it doesn't appear to work and comes back with "the specified device name is invalid". Is there another bit of the code I should be altering. Also yes it will always be the same letter "Dave Peterson" wrote: Always using the same drive letter and the same path??? Option Explicit Sub testme() Dim res As Variant res = TryToMapIt("G", "\\myserver\mypath") If res = True Then MsgBox "it worked" Else MsgBox res End If End Sub Function TryToMapIt(myDrive, NewPath) As Variant Dim FixedIt As Variant Dim FSO As Object Dim WSHNetwork As Object Set WSHNetwork = CreateObject("WScript.Network") Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.driveexists(myDrive) Then WSHNetwork.RemoveNetworkDrive myDrive, True, True End If FixedIt = False On Error Resume Next WSHNetwork.MapNetworkDrive myDrive, NewPath, True If Err.Number = 0 Then FixedIt = True Else If Err.Number < 0 Then FixedIt = Err.Description End If Err.Clear End If TryToMapIt = FixedIt End Function Popeye the powerman wrote: Gents, Is there a way to write a macro that when its run it will map a network drive. it needs to also include the reconnect at logon. This will save me having to tell people how to do it all the time regards Popeye -- Dave Peterson -- Dave Peterson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
using a macro to map a shared drive
I don't see how this would work, but the other not...
But glad you got something working. Popeye the powerman wrote: Dave, Found this on the scripting forum & does what I wanted Share = "\\Drive\Group" Set objNetwork = CreateObject("Wscript.Network") objNetwork.MapNetworkDrive "Z:", Share Thanks for your assistance Popeye "Dave Peterson" wrote: Try connecting (and disconnecting manually). Then share the details of what worked manually. Then share how you changed the code. The code worked for me in the past -- but I don't have access to a network, so I won't be able to do any real testing. But if you post what you tried, maybe some reader will see a typo... Popeye the powerman wrote: Dave, I assume I replace ("G", "\\myserver\mypath") with my drive letter and server if thats the case it doesn't appear to work and comes back with "the specified device name is invalid". Is there another bit of the code I should be altering. Also yes it will always be the same letter "Dave Peterson" wrote: Always using the same drive letter and the same path??? Option Explicit Sub testme() Dim res As Variant res = TryToMapIt("G", "\\myserver\mypath") If res = True Then MsgBox "it worked" Else MsgBox res End If End Sub Function TryToMapIt(myDrive, NewPath) As Variant Dim FixedIt As Variant Dim FSO As Object Dim WSHNetwork As Object Set WSHNetwork = CreateObject("WScript.Network") Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.driveexists(myDrive) Then WSHNetwork.RemoveNetworkDrive myDrive, True, True End If FixedIt = False On Error Resume Next WSHNetwork.MapNetworkDrive myDrive, NewPath, True If Err.Number = 0 Then FixedIt = True Else If Err.Number < 0 Then FixedIt = Err.Description End If Err.Clear End If TryToMapIt = FixedIt End Function Popeye the powerman wrote: Gents, Is there a way to write a macro that when its run it will map a network drive. it needs to also include the reconnect at logon. This will save me having to tell people how to do it all the time regards Popeye -- Dave Peterson -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro not always when opened from shared drive | Excel Programming | |||
Macro - Share with Users on a shared network drive | Excel Programming | |||
Printing viewing a shared workbook on a shared drive | Excel Discussion (Misc queries) | |||
Shared Drive/Macro or Hyperlink | Excel Programming | |||
Create folders on a shared drive with a macro | Excel Programming |