how can I ..... ?

E

emma

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
 
C

Chip Pearson

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
 
T

Tom Ogilvy

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
 

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