×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Map Network Drive

Map Network Drive

Map Network Drive

(OP)
with the code here:
http://www.tek-tips.com/viewthread.cfm?qid=1012208
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
WshNetwork.RemoveNetworkDrive "L:"
'"WshNetwork is not a record type" is the error i get when i try to compile
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

RE: Map Network Drive



hi,

Why use a drive?

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

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Map Network Drive

(OP)
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

RE: Map Network Drive



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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Map Network Drive

(OP)
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

RE: Map Network Drive



Quote:

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")
    '
    xlFile = "\\dfwsrv222\public\MyStuff\abc.xls"   'this path is CONSTANT regardless of mapped drives!
    '

    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,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: Map Network Drive

(OP)
now i understand. Thanks a lot!

rem

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close