Consulting

Results 1 to 3 of 3

Thread: ChDrive without mapping

  1. #1
    VBAX Regular
    Joined
    Nov 2008
    Posts
    25
    Location

    ChDrive without mapping

    Hi

    Normally to switch to a new drive (x, I can just write
    chdrive "x:"

    Howver I have access to a drive that is not mapped
    So when I access the files, I have a link like
    \\accounts\finance etc

    I have tried to use chdrive \\accounts\finance but this does not work

    Does anyone have the correct syntax when a drive is not mapped?
    I don;t want to map it permanently because I get new drives all the time. So it might conflict with a new one

    Thanks

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    http://www.ozgrid.com/forum/showthre...t=32173&page=1

    Andy Pope's #6

    As CHDIR() will not work with UNC directories try this example using an API. Change the servername and sharename to suit.

    [vba]
    Private Declare Function SetCurrentDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long

    Sub xx()
    SetUNCPath "\\servername\sharedname"
    End Sub

    Sub SetUNCPath(Path As String)
    Dim lngStatus As Long

    lngStatus = SetCurrentDirectoryA(Path)
    If lngStatus = 0 Then
    MsgBox "Could not set path" & vbLf & Path, vbExclamation
    End If

    End Sub
    [/vba]

    I haven't tried it yet, but I have faith in Andy

    I'll also put it into my collection of subs, since I need to get data off of UNC drives also

    Paul

  3. #3
    VBAX Regular
    Joined
    Nov 2008
    Posts
    25
    Location
    Thanks Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •