Map drive to open a file with code

L

Les Stout

Hello all, is it possible to "map" to a network drive, open a file and
then "disconnect" the drive again with code ? This is necessary as not
all users have access to the drive which is also password protected.

Any help would be appreciated...

Best regards,

Les Stout
 
D

Dave Peterson

Why not just open the file via the UNC name.

You can do it in the file|open dialog or you can do it in code:

Dim wkbk as workbook
set wkbk = workbooks.open(Filename:="\\server\share\folder\file.xle")
 
L

Les Stout

Hello Dave, this drive is not mapped in all cases... I tried your
suggestion but it does not find the file and it is there. If i map the
drive then it works fine but that is the initial problem...

Best regards,

Les Stout
 
D

Dave Peterson

The drive doesn't need to be mapped to a letter if you refer to it by its UNC
path.

Try recording a macro when you open the file manually using that UNC path.

Maybe you mistyped something in the code and the recorded macro will help you
find it.
 

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

Top