ChDir statement

N

neta

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 !
 
R

Ron de Bruin

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top