ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Change directory (https://www.excelbanter.com/excel-discussion-misc-queries/111774-change-directory.html)

Jeff

Change directory
 
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!

Gary''s Student

Change directory
 
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.
--
Gary's Student


"Jeff" wrote:

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!


Stefi

Change directory
 
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:

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!


Jeff

Change directory
 
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?


"Gary''s Student" wrote:

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.
--
Gary's Student


"Jeff" wrote:

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!


Stefi

Change directory
 
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:

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!


Jeff

Change directory
 
Unfortunately, I am using excel 97, so that method doesn't work.

But thanks for your help!

"Stefi" wrote:

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:

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!


Dave Peterson

Change directory
 
Jim Rech has a BrowseForFolder routine at:
http://www.oaltd.co.uk/MVP/Default.htm
(look for BrowseForFolder)

John Walkenbach has one at:
http://j-walk.com/ss/excel/tips/tip29.htm

Jeff wrote:

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!


--

Dave Peterson


All times are GMT +1. The time now is 05:44 PM.

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