Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Selecting a Directory

Hi All
On a userform I have a textbox control in which I let the user store the
destination directory for the file(s) created. I have been using
Application.GetOpenFilename to let the user go and find the directory and
choose a file - I then strip the filename leaving the path only and put this
in the control.

It is not elegant since the user has to choose a file to open (anyone will
do) so I can extract the path, problem #1 is that user is now being asked to
open a file which doesn't actually happen just so I can get the directory -
all a bit confusing for them (and me!).

Aside from that, if the directory is empty there are no files to select - so
problem #2 they cannot select this directory.

Anyone got a solution please?

--
Cheers
Nigel




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Selecting a Directory

You could use application.getsaveasfilename. The file doesn't have to exist.

Option Explicit
Sub testme()

Dim myFolderName As Variant
myFolderName = Application.GetSaveAsFilename _
(InitialFileName:="FileNameWillBeIgnored")

If myFolderName = False Then
Exit Sub 'user hit cancel
Else
'your routine to strip out filename
End If
End Sub

Or you could use one of these routines...

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


===
ps. If you and all your users are running xl2002+, take a look at VBA's help:
application.filedialog(msoFileDialogFolderPicker)




Nigel wrote:

Hi All
On a userform I have a textbox control in which I let the user store the
destination directory for the file(s) created. I have been using
Application.GetOpenFilename to let the user go and find the directory and
choose a file - I then strip the filename leaving the path only and put this
in the control.

It is not elegant since the user has to choose a file to open (anyone will
do) so I can extract the path, problem #1 is that user is now being asked to
open a file which doesn't actually happen just so I can get the directory -
all a bit confusing for them (and me!).

Aside from that, if the directory is empty there are no files to select - so
problem #2 they cannot select this directory.

Anyone got a solution please?

--
Cheers
Nigel


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Selecting a Directory

Thanks Dave, good tip. I tried and used John Walkenbach version which is
ideal - thanks John

--
Cheers
Nigel



"Dave Peterson" wrote in message
...
You could use application.getsaveasfilename. The file doesn't have to

exist.

Option Explicit
Sub testme()

Dim myFolderName As Variant
myFolderName = Application.GetSaveAsFilename _
(InitialFileName:="FileNameWillBeIgnored")

If myFolderName = False Then
Exit Sub 'user hit cancel
Else
'your routine to strip out filename
End If
End Sub

Or you could use one of these routines...

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


===
ps. If you and all your users are running xl2002+, take a look at VBA's

help:
application.filedialog(msoFileDialogFolderPicker)




Nigel wrote:

Hi All
On a userform I have a textbox control in which I let the user store the
destination directory for the file(s) created. I have been using
Application.GetOpenFilename to let the user go and find the directory

and
choose a file - I then strip the filename leaving the path only and put

this
in the control.

It is not elegant since the user has to choose a file to open (anyone

will
do) so I can extract the path, problem #1 is that user is now being

asked to
open a file which doesn't actually happen just so I can get the

directory -
all a bit confusing for them (and me!).

Aside from that, if the directory is empty there are no files to

select - so
problem #2 they cannot select this directory.

Anyone got a solution please?

--
Cheers
Nigel


--

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
Directory Jeff Excel Discussion (Misc queries) 1 October 5th 06 04:51 PM
Creating a macro that lists directory names within a directory.... Andy Excel Programming 4 November 28th 04 06:13 AM
Selecting a directory from a form in excel ennui Excel Programming 6 April 2nd 04 01:47 AM
Directory "Locked" when selecting multiple files using GetOpenFilename esbey Excel Programming 1 March 4th 04 04:29 AM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM


All times are GMT +1. The time now is 08:30 PM.

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"