ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how can I ..... ? (https://www.excelbanter.com/excel-programming/282739-how-can-i.html)

emma

how can I ..... ?
 
I have in Sheet1 in A1 the following

= "\\SharedDocs\Test01"
in A2 = "\\SharedDocs\Test02"

How can I in the code assign a variable to chage to that
directory

Now what I have to change the directory is:
ChDir "\\SharedDocs\Test01 "

but I want to have something like that :

ChDir "variable" (what it is in A1 for example)

thanks a lot
emma

Chip Pearson

how can I ..... ?
 
Emma,

The following will call ChDir to use whatever is in A1:

ChDir ActiveSheet.Range("A1").Text

You can also use a variable to do this. E.g.,

Dim S As String
S = "\\SharedDocs\Test01 "
ChDir S


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"emma" wrote in message
...
I have in Sheet1 in A1 the following

= "\\SharedDocs\Test01"
in A2 = "\\SharedDocs\Test02"

How can I in the code assign a variable to chage to that
directory

Now what I have to change the directory is:
ChDir "\\SharedDocs\Test01 "

but I want to have something like that :

ChDir "variable" (what it is in A1 for example)

thanks a lot
emma




Tom Ogilvy

how can I ..... ?
 
Does chdir work with
ChDir "\\SharedDocs\Test01 "

If so, then Chip gave you the answer, but in my experience, it does not work
with a UNC path.


Previously posted by Rob Bovey - place in the top of a general/standard
module:

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

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

Usage would be like this:

ChDirNet "\\LOGD0FILES\OGILVTW\Docs\Temp"
Application.Dialogs(xlDialogFindFile).Show
End Sub

--
Regards,
Tom Ogilvy


"emma" wrote in message
...
I have in Sheet1 in A1 the following

= "\\SharedDocs\Test01"
in A2 = "\\SharedDocs\Test02"

How can I in the code assign a variable to chage to that
directory

Now what I have to change the directory is:
ChDir "\\SharedDocs\Test01 "

but I want to have something like that :

ChDir "variable" (what it is in A1 for example)

thanks a lot
emma





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

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