#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default 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!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default 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!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,646
Default 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!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default 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!

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,646
Default 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!



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default 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!

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want cell ref. to change after sort in other sheet Bullfn33 Excel Discussion (Misc queries) 1 August 6th 06 05:48 PM
How can I change list into a directory format? Becky Ed Excel Worksheet Functions 1 August 3rd 06 05:25 PM
Formula Link References Change to Startup Directory Martha Links and Linking in Excel 3 July 3rd 06 02:19 PM
Takes too long for Filedialog to change directory File selection in office2003 Excel Discussion (Misc queries) 1 May 1st 06 05:33 AM
change directory for refresh data TxRaistlin Excel Discussion (Misc queries) 0 February 7th 05 09:09 PM


All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"