Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prompt user for folder or path 1

Status
Not open for further replies.

yippiekyyay

Programmer
Oct 26, 2002
186
CA
With help from this forum, I’ve written a macro which will create separate documents for each record in a mail merge. I’ve specified the folder where to place the files (ChangeFileOpenDirectory "C:\mail_merged_files_folder\"), but I’d rather a window open up that asks the user to specify a folder of their choice.

Basically, I’m going for something like this:
Code:
Dim myFolderPath As String
myFolderPath = ???
ChangeFileOpenDirectory myFolderPath

Thanks in advance!
 





Hi,

What application?

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
In any VBA application you may use this function:
Code:
Function PickFolder(strStartDir As Variant) As String
Dim SA As Object, f As Object
Set SA = CreateObject("Shell.Application")
Set f = SA.BrowseForFolder(0, "Choose a folder", 16 + 32 + 64, strStartDir)
If (Not f Is Nothing) Then
  PickFolder = f.Items.Item.path
End If
Set f = Nothing
Set SA = Nothing
End Function

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Reference shell32.dll:

Dim fName As String
Dim shellApp As Shell32.Shell
Set shellApp = New Shell32.Shell
fName = shellApp.BrowseForFolder(0, "Please choose/create a folder", 0).Title
' (last arg. 512 instead of 0 to disable new folder)
MsgBox fName


combo
 
For full path in above code replace 'Title' by 'Self.Path'

combo
 
Thank you all very much!

Yes it was for Word and PHV's code worked great (I'll try yours as well in a minute combo).

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top