+ Reply to Thread
Results 1 to 5 of 5

ChDir statement

  1. #1
    Registered User
    Join Date
    03-26-2004
    Posts
    35

    ChDir statement

    Hi,

    I am using the "chdir" statement in VBA - in the "before open" private sub. the statement does not work - the default directory does not change (stay as "my document").

    In the help it is written that The ChDir statement changes the default directory but not the default drive.

    Any ideas ?

    Thanks a lot !

  2. #2
    Ron de Bruin
    Guest

    Re: ChDir statement

    Use

    MyPath = ThisWorkbook.Path
    ChDrive MyPath
    ChDir MyPath

    This is not working for a network folder

    Use this then

    Private Declare Function SetCurrentDirectoryA Lib _
    "kernel32" (ByVal lpPathName As String) As Long

    Public Sub ChDirNet(szPath As String)
    ' Rob Bovey
    Dim lReturn As Long
    lReturn = SetCurrentDirectoryA(szPath)
    If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
    End Sub


    And this in your code

    ChDirNet "\\ComputerName\YourFolder"



    --
    Regards Ron De Bruin
    http://www.rondebruin.nl



    "neta" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi,
    >
    > I am using the "chdir" statement in VBA - in the "before open" private
    > sub. the statement does not work - the default directory does not
    > change (stay as "my document").
    >
    > In the help it is written that The ChDir statement changes the default
    > directory but not the default drive.
    >
    > Any ideas ?
    >
    > Thanks a lot !
    >
    >
    > --
    > neta
    > ------------------------------------------------------------------------
    > neta's Profile: http://www.excelforum.com/member.php...fo&userid=7624
    > View this thread: http://www.excelforum.com/showthread...hreadid=552335
    >




  3. #3
    Ron de Bruin
    Guest

    Re: ChDir statement

    Use

    MyPath = ThisWorkbook.Path
    ChDrive MyPath
    ChDir MyPath

    This is not working for a network folder

    Use this then

    Private Declare Function SetCurrentDirectoryA Lib _
    "kernel32" (ByVal lpPathName As String) As Long

    Public Sub ChDirNet(szPath As String)
    ' Rob Bovey
    Dim lReturn As Long
    lReturn = SetCurrentDirectoryA(szPath)
    If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
    End Sub


    And this in your code

    ChDirNet "\\ComputerName\YourFolder"



    --
    Regards Ron De Bruin
    http://www.rondebruin.nl



    "neta" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi,
    >
    > I am using the "chdir" statement in VBA - in the "before open" private
    > sub. the statement does not work - the default directory does not
    > change (stay as "my document").
    >
    > In the help it is written that The ChDir statement changes the default
    > directory but not the default drive.
    >
    > Any ideas ?
    >
    > Thanks a lot !
    >
    >
    > --
    > neta
    > ------------------------------------------------------------------------
    > neta's Profile: http://www.excelforum.com/member.php...fo&userid=7624
    > View this thread: http://www.excelforum.com/showthread...hreadid=552335
    >




  4. #4
    Registered User
    Join Date
    03-21-2013
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    1

    Thumbs up Re: ChDir statement

    Ron - You ROCK...thx for help with this...yes...7 years later it helped someone!




    Quote Originally Posted by Ron de Bruin View Post
    Use

    MyPath = ThisWorkbook.Path
    ChDrive MyPath
    ChDir MyPath

    This is not working for a network folder

    Use this then

    Private Declare Function SetCurrentDirectoryA Lib _
    "kernel32" (ByVal lpPathName As String) As Long

    Public Sub ChDirNet(szPath As String)
    ' Rob Bovey
    Dim lReturn As Long
    lReturn = SetCurrentDirectoryA(szPath)
    If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
    End Sub


    And this in your code

    ChDirNet "\\ComputerName\YourFolder"



    --
    Regards Ron De Bruin
    http://www.rondebruin.nl



    "neta" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hi,
    >
    > I am using the "chdir" statement in VBA - in the "before open" private
    > sub. the statement does not work - the default directory does not
    > change (stay as "my document").
    >
    > In the help it is written that The ChDir statement changes the default
    > directory but not the default drive.
    >
    > Any ideas ?
    >
    > Thanks a lot !
    >
    >
    > --
    > neta
    > ------------------------------------------------------------------------
    > neta's Profile: http://www.excelforum.com/member.php...fo&userid=7624
    > View this thread: http://www.excelforum.com/showthread...hreadid=552335
    >

  5. #5
    Registered User
    Join Date
    08-19-2013
    Location
    Cologne, Germany
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: ChDir statement

    Yes. Yes, it did.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1