Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / April 2007

Tip: Looking for answers? Try searching our database.

Mapping network drive...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gojavid - 24 Apr 2007 19:09 GMT
Is there a way to map a network drive in a macro?
Harlan Grove - 24 Apr 2007 20:06 GMT
"Gojavid" <david.lachowsky@gmail.com> wrote...
>Is there a way to map a network drive in a macro?

Shell "net use x: \\computername\directory\subdirectory\..."
Dave Peterson - 24 Apr 2007 20:21 GMT
One more:

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

> Is there a way to map a network drive in a macro?

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.