I've created VBA code so that a group of people in our company can "stamp" a word document with a unique number stored in an Excel sheet on a network drive (essentially giving a serial#). These people do not have access to said network drive, but I'd like them to be able to execute the VBA code.
I've been reading over various articles on this site and others for the last couple days, and was able to adapt this post to work for me. However, if I try and execute the VBA code more than once, I get the "multiple connections" error described in the original answer. It seems, then, that the mapped drive is not being removed. Is this a simple syntax issue? Or am i missing something in my RemoveNetworkDrive
statement?
ServerShare = "\\Servername\path"
UserName = "domain\username"
Password = "password"
Set NetworkObject = CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password
str_WbPath = ServerShare & "\MRL Number Generator.xlsm"
Set exWb = objExcel.Workbooks.Open(str_WbPath)
'Do Stuff in excel
Set exWb = Nothing
Set FSO = Nothing
NetworkObject.RemoveNetworkDrive ServerShare, True, False
Set NetworkObject = Nothing