Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro not always when opened from shared drive Emma Excel Programming 3 June 5th 08 03:28 PM
Macro - Share with Users on a shared network drive Vicki Excel Programming 4 September 17th 07 09:28 PM
Printing viewing a shared workbook on a shared drive aloomba Excel Discussion (Misc queries) 0 April 13th 07 02:52 PM
Shared Drive/Macro or Hyperlink Hargrove[_2_] Excel Programming 2 June 14th 04 06:49 PM
Create folders on a shared drive with a macro Michael McClellan Excel Programming 2 June 1st 04 11:58 PM


All times are GMT +1. The time now is 10:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"