Hi Kevsim,
PHV is correct but, perhaps, some explanation.
You are asking for an object of type "WScript.Network" to be created. This doesn't just happen, it is an action (or a "Method") that is performed by another, existing, object. In your code you are asking that some object, referenced by
WScript, perform this action for you, and you are being told that WScript is not an object.
If you think WScript should be referencing an object then you need to look at the rest of your code to find out why it doesn't. If WScript is just something you've copied from somewhere else and unrelated to the rest of your code then you need, instead, to ask some other object, to which you do have a reference, to create the new object for you. This is what PH's code does - by not explicitly specifying an object, he is requesting the default object, the Application (Word or Excel or whatever you're using) perform the action.
This works in this case because the Application does know how to do it - creating a new object is a fairly generic type action that most objects can perform. In the general case, of course, you must ask an appropriate object to do the action you want. So, for example, the Method you actually want to use,
MapNetworkDrive cannot be performed by the Application which is why you have to create a specialised object to do it.
One final note. When you have done with the object you have created you should explicitly destroy it:
Code:
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "L:", "\\mydrive\share"
Set WshNetwork = Nothing
Enjoy,
Tony
--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[