Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map Network Drive 1

Status
Not open for further replies.

remy988

Technical User
Mar 29, 2012
128
US
with the code here:
i'm able to map a drive with vba. is there an equivalent code with EB
Code:
Set WshNetwork = CreateObject("WScript.Network")

On Error Resume Next
[blue]WshNetwork.RemoveNetworkDrive "L:"[/blue]
[red]'"WshNetwork is not a record type" is the error i get when i try to compile[/red]
On Error GoTo 0

WshNetwork.MapNetworkDrive "L:", "\\mydrive\share" 'HardDrive"

Set WshNetwork = Nothing

"WshNetwork is not a record type" is the error i get when i try to compile

thanks

rem
 


hi,

Why use a drive?

Why not just use "\\mydrive\share\......." as your path, filename?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
hi SkipVought,
thank you for looking at this. i have a macro that access the network drive to retrieve a file. if the network drive is not mapped, the macro would fail.
i know i can first map the drive, then run the macro. but i was hoping that i can map the drive with EB. Unfortunately i cannot use VBA for this particular script.


rem
 


The problem with using DRIVES is that users can map drives differerntly. I NEVER use drives when accessing files in code. The DRIVE is really unnecessary when accessing NETWORK data.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
here is my code
Code:
Sub Main
    Dim obj as object
    Dim objWorkbook as object
    Dim xlFile As String
    
    Set obj=CreateObject("Excel.Application")
    xlFile = "S:\MyStuff\abc.xls"

    Set obj = getobject(xlFile) 
    set objWorkbook=obj.Worksheets("sheet1")
    
    myacct = = objWorkBook.Range("b2").value
    
    'dostuff here

    set obj  = Nothing
    set objWorkbook = Nothing
    

End Sub

how can i modify it to access the file without a drive?
the location of my file will always be on S

i'm not sure what you mean "\\mydrive\share\......."

rem
 


WshNetwork.MapNetworkDrive "L:", "\\mydrive\share" 'HardDrive"
The CONSTANT is the network share. The VARIABLE is the drive designation.

I ABSOLUTELY KNOW, for instance that I can find a file on our company network...
Code:
    Dim obj As Object
    Dim objWorkbook As Object
    Dim xlFile As String
    Dim myacct As String
    
    Set obj = CreateObject("Excel.Application")
    '[b]
    xlFile = "\\dfwsrv222\public\MyStuff\abc.xls"   'this path is CONSTANT regardless of mapped drives!
    '[/b]
    Set objWorkbook = obj.Workbooks.Open(xlFile)
    
    myacct = objWorkbook.Worksheets(1).Range("b2").Value
    
    'dostuff here

    objWorkbook.Close
    Set objWorkbook = Nothing
    
    obj.Quit
    Set obj = Nothing


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top