PC Review


Reply
Thread Tools Rate Thread

API for a user to select a folder?

 
 
Chrisso
Guest
Posts: n/a
 
      1st Aug 2008
Hi All

Is there an API call similar to Application.GetOpenFileName that will
allow a user to select a folder and then return the selected folder as
a String?

Thanks,
Chrisso
 
Reply With Quote
 
 
 
 
Tom Hutchins
Guest
Posts: n/a
 
      1st Aug 2008
Here are two ways...

Sub AAAA()
Dim oApp As Object, oFolder
Set oApp = CreateObject("Shell.Application")
'Browse to the folder
Set oFolder = oApp.BrowseForFolder(0, "Select folder", 512)
If Not oFolder Is Nothing Then
'Do whatever
Else
MsgBox "You did not select a folder"
End If
'carry on...
End Sub

Sub BBBB()
'Declare variables for this macro.
Dim Fyle As String, FylePath As String, xx As Integer
'The user needs to select any file in the folder.
Fyle$ = Application.GetOpenFilename("All Files (*.*), *.*", , _
"Select any file in the desired folder")
'If no file was selected (Cancel clicked), stop the macro.
If Fyle$ = "False" Then Exit Sub
'Extract just the file path from Fyle$.
FylePath$ = vbNullString
For xx% = Len(Fyle$) To 1 Step -1
If Mid(Fyle$, xx%, 1) = "\" Then
FylePath$ = Left(Fyle$, xx%)
Exit For
End If
Next xx%
If Len(FylePath$) = 0 Then
MsgBox "Cannot identify file path"
Exit Sub
End If
'carry on...
End Sub

Hope this helps,

Hutch

"Chrisso" wrote:

> Hi All
>
> Is there an API call similar to Application.GetOpenFileName that will
> allow a user to select a folder and then return the selected folder as
> a String?
>
> Thanks,
> Chrisso
>

 
Reply With Quote
 
Richard MG
Guest
Posts: n/a
 
      4th Aug 2008
Chrisso wrote "Is there an API call similar to Application.GetOpenFileName
that will
> allow a user to select a folder and then return the selected folder as
> a String?"


What if the user just needs to open a file in the selected folder which will
then run in its usual programme independantly of Excel. All the solutions I
have seen give a way of selecting the file path. How do I get the file to
open in the correct programme, i.e. .xlm file opening in Infopath. I am using
Excel 2003 and Infopath 2007


"Chip Pearson" wrote:

> See http://www.cpearson.com/Excel/BrowseFolder.aspx for example code.
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft Most Valuable Professional
> Excel Product Group
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on web site)
>
>
>
>
> "Chrisso" <(E-Mail Removed)> wrote in message
> news:b0b5571e-8c2a-4568-bf8c-(E-Mail Removed)...
> > Hi All
> >
> > Is there an API call similar to Application.GetOpenFileName that will
> > allow a user to select a folder and then return the selected folder as
> > a String?
> >
> > Thanks,
> > Chrisso

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
User select folder name MJKelly Microsoft Excel Programming 1 6th Oct 2009 10:35 PM
Allow the user to select a folder Kuldeep Microsoft ASP .NET 2 29th Jun 2007 05:01 PM
Dialog box for user to select a folder =?Utf-8?B?aG1t?= Microsoft Excel Programming 6 22nd Nov 2006 10:09 AM
User select Save To Folder =?Utf-8?B?QnJhZA==?= Microsoft Excel Programming 4 16th Nov 2006 09:06 PM
allow user to select folder jbhoop Microsoft Excel Misc 3 3rd Jan 2006 10:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:54 PM.