using a macro to map a drive

  • Thread starter asa.flynt.reynolds
  • Start date
A

asa.flynt.reynolds

I am looking for a way to map a network drive with a macro when a user
opens a spreadsheet. Then when the user is done using the
spreadsheet, another macro would disconnect the mapped drive. Does
anyone know of a way to accomplish this? Any help would be
appreciated.
 
G

Guest

Have the workbook open event macro call something like this:

Sub mapp_um()
dq = Chr(34)
s = "net use z: /delete /y"
ss = "net use z: " & dq & "\\myServ\Shared" & dq & " /PERSISTENT:no"
x = Shell("cmd.exe /c" & s, 1)
x = Shell("cmd.exe /c" & ss, 1)
End Sub

In this example I used Z: as the drive. The initial delete is just in case
Z: is already being used.

Trap the workbook close event and have it call something like:

Sub unmap()
dq = Chr(34)
s = "net use z: /delete /y"
x = Shell("cmd.exe /c" & s, 1)
End Sub

This releases Z:
 
D

Dave Peterson

Just curious why you have to map that drive. I would think that most things
(all things???) would work ok if you used the UNC path.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top