Change directory

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I was using the ChDir = "C:\Temp" to change the directory
Is there anyway to specify the directory, and then save the path as a
string. I was trying.

myFileName = Application.GetOpenFilename("Excel Files, *.xls")
y = Dir(myFileName, vbDirectory)

but y was just set to the filename, I wanted the path like "C:\Temp"

Thanks for your help!
 
Your code (which works) results in myFileName containing something like:

C:\Temp\Inside\whatever.xls

a string with the full path and file name. You can get the individual parts
by splitting the string on the last backslash.
 
Hi Jeff,
Try this method (it works only in XL2003):

Sub test()
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = 0 Then
y = ""
Else
y = .SelectedItems(1)
End If
End With
End Sub

Regards,
Stefi


„Jeff†ezt írta:
 
The problem I was having was if there was a folder with no files in it.

My first step was to create a new folder and then populate it, but it is a
problem here because there are no files there yet.

Any suggestions?
 
Hi Jeff,

Try this method:

Sub test()
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = 0 Then
y = ""
Else
y = .SelectedItems(1)
End If
End With
End Sub

Regards,
Stefi

„Jeff†ezt írta:
 
Unfortunately, I am using excel 97, so that method doesn't work.

But thanks for your help!
 

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

Back
Top