ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   chdir not accepting string for path (https://www.excelbanter.com/excel-programming/313416-chdir-not-accepting-string-path.html)

Alan

chdir not accepting string for path
 
Hi all,

Consider the following:

Dim MyPath as String
MyPath = "\\xxx\yyy"

If I execute ChDir MyPath, I get a "Can't find path" error. But if I execute
ChDir "\\xxx\yyy", I don't get an error. I've also used
SetCurrentDirectoryA(MyPath)
with the same nasty result. Passing a quoted path string, however, works.

Any idea what is going on??? It seems to be central to using a network path
name.

TIA
Alan

Ron de Bruin

chdir not accepting string for path
 
Hi Alan

Try this

'Previously posted by Rob Bovey:

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

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

' sample usage

Sub FindFile()
Dim FName As Variant

ChDirNet "\\DELL\testing"
FName = Application.GetOpenFilename
End Sub




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


"Alan" wrote in message ...
Hi all,

Consider the following:

Dim MyPath as String
MyPath = "\\xxx\yyy"

If I execute ChDir MyPath, I get a "Can't find path" error. But if I execute
ChDir "\\xxx\yyy", I don't get an error. I've also used
SetCurrentDirectoryA(MyPath)
with the same nasty result. Passing a quoted path string, however, works.

Any idea what is going on??? It seems to be central to using a network path
name.

TIA
Alan





All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com