I know this is probably a stupid question, but I am trying to deploy a macro written (and working!) in Excel 10 on a Office 2000 machine. The macro simply displays a dialog to allow choice of a folder (Folder picker in FileDialog), then itereates through all the images in the file inserting them into the spreadsheet together with some text etc. Works fine on the Office XP machines, but FileDialog seems to be in the Office 10 library, and I can’t find any simple way of doing the same thing.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Filedialog equivalent in office 9 (Office 9)
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Filedialog equivalent in office 9 (Office 9)
- This topic has 36 replies, 9 voices, and was last updated 20 years, 10 months ago.
Viewing 2 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerJuly 2, 2003 at 11:19 am #690691(Edited by HansV on 02-Jul-03 14:19. Had left some Access-specific code. Also see Pieterse’s reply in this thread.)
You can put the following code in a standard module:
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End TypePrivate Declare Function SHGetPathFromIDList Lib “shell32.dll” Alias “SHGetPathFromIDListA” _
(ByVal pidl As Long, ByVal pszPath As String) As LongPrivate Declare Function SHBrowseForFolder Lib “shell32.dll” Alias “SHBrowseForFolderA” _
(lpBrowseInfo As BROWSEINFO) As LongPrivate Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As IntegerWith bi
.hOwner = 0 ‘ had hWndAccessApp here, which is for Access only
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End WithdwIList = SHBrowseForFolder(bi)
szPath = Space$(512)If SHGetPathFromIDList(ByVal dwIList, ByVal szPath) Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos – 1)
End If
End FunctionYou can let the user pick a folder as follows:
Dim strFolder As String
strFolder = BrowseFolder(“Select a folder”)If the user clicked Cancel, strFolder will be the empty string “”.
-
WSpieterse
AskWoody LoungerJuly 2, 2003 at 11:15 am #690692And to make this work in Excel:
Option Explicit
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End TypePrivate Declare Function FindWindow32 Lib “user32” Alias “FindWindowA” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SHGetPathFromIDList Lib “shell32.dll” Alias “SHGetPathFromIDListA” _
(ByVal pidl As Long, ByVal pszPath As String) As LongPrivate Declare Function SHBrowseForFolder Lib “shell32.dll” Alias “SHBrowseForFolderA” _
(lpBrowseInfo As BROWSEINFO) As LongPrivate Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
Dim bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer
Dim hwndXL As Long
hwndXL = FindWindow32(“XLMAIN”, Application.Caption)
‘ For Word:
‘ hwndXL = FindWindow32(“OPUSAPP”, Application.Caption)
‘ Of course hwndXL looks funy in Word
With bi
.hOwner = hwndXL
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End WithdwIList = SHBrowseForFolder(bi)
szPath = Space$(512)If SHGetPathFromIDList(ByVal dwIList, ByVal szPath) Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos – 1)
End If
End FunctionSub example()
Dim strFolder As String
strFolder = BrowseFolder(“Select a folder”)End Sub
-
WSHansV
AskWoody Lounger -
WSpieterse
AskWoody Lounger -
WSpieterse
AskWoody Lounger -
WSHansV
AskWoody Lounger
-
-
-
WSKevin
AskWoody LoungerJuly 2, 2003 at 5:45 pm #690792
-
-
-
WSpaulw
AskWoody LoungerJuly 2, 2003 at 2:35 pm #690730Thanks both of you – leads to 4 conclusions 1) I see why they put FileDialog into 10, 2) I don’t see why it took them until Office 10!, 3) I feel MUCH better about not being able to figure out how to do it, and 4) there are some really generous people in the lounge with a lot of knowledge they willing to share.
I have a feeling that reading this code will advance my knowledge of VBA significantly (and believe me it needs that!)
Thanks again. -
WSDon Ceraso
AskWoody LoungerJuly 3, 2003 at 4:07 am #690903In stead of all those API functions you can use the following mini code:
Sub Test()
Debug.Print GetFolder(Title:=”Gimme a Folder”, RootFolder:=&H11)
End SubFunction GetFolder(Optional Title As String = “Select a Folder”, Optional RootFolder As Variant) As String
On Error Resume Next
GetFolder = CreateObject(“Shell.Application”).BrowseForFolder(0, Title, 0, RootFolder).Items.Item.Path
End Function -
WSpieterse
AskWoody Lounger -
WSIvan F Moala
AskWoody Lounger -
WSdane_walther
AskWoody Lounger -
WSjscher2000
AskWoody LoungerJuly 1, 2004 at 5:51 pm #846721Which API are you using?
Andrew Cronnolly’s post 179268 shows how, if you are using BrowseForFolder, you can trick it into letting you pick files. The example is in VBScript, but the principle should apply equally well to other contexts.
-
WSdane_walther
AskWoody LoungerJuly 1, 2004 at 6:36 pm #846732Andrew also states that it is kind of unpredictable on some platforms (XP, for one). Since this potentially will be used by others in my location once it’s operational, I don’t have much of a control over what OS version it’s running on. But we do all have Office 2000 (v9)…
thanks,
..dane -
WSjscher2000
AskWoody Lounger -
WSjscher2000
AskWoody Lounger
-
-
WSdane_walther
AskWoody LoungerJuly 1, 2004 at 6:36 pm #846733Andrew also states that it is kind of unpredictable on some platforms (XP, for one). Since this potentially will be used by others in my location once it’s operational, I don’t have much of a control over what OS version it’s running on. But we do all have Office 2000 (v9)…
thanks,
..dane
-
-
WSjscher2000
AskWoody LoungerJuly 1, 2004 at 5:51 pm #846722Which API are you using?
Andrew Cronnolly’s post 179268 shows how, if you are using BrowseForFolder, you can trick it into letting you pick files. The example is in VBScript, but the principle should apply equally well to other contexts.
-
WSJohnBF
AskWoody LoungerJuly 1, 2004 at 5:52 pm #846706(Edited by JohnBF on 01-Jul-04 11:52. Outlook doesn’t support the Method. Available only in Ofiice 10+.)
Funny you should ask. This works in Excel but won’t run in Outlook, because the App doesn’t support the FileDialog method.
Sub TestBrowse4file()
MsgBox Browse4File
End SubPrivate Function Browse4File() As String
Dim dlgOpen As FileDialog
Dim varFile As Variant
Dim strReturnedPath As StringSet dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
.AllowMultiSelect = False
.Show
For Each varFile In .SelectedItems
strReturnedPath = varFile
Next varFile
End With
Browse4File = strReturnedPath & CStr(varFile)End Function
I’m sure it needs more work.
-
WSdane_walther
AskWoody Lounger -
WSJohnBF
AskWoody LoungerJuly 1, 2004 at 8:11 pm #846754(Edited by JohnBF on 01-Jul-04 14:11. )
Try the code here, but edit this line:
.lpstrFilter = “Image Files” + Chr(0) + “*.bmp;*.jpg;*.jpeg;*.jpe” + _
Chr(0) + “All Files (*.*)” + Chr(0) + “*.*” + Chr(0) + Chr(0)according to the target file type, such as all:
.lpstrFilter = “All Files (*.*)” + Chr(0) + “*.*” + Chr(0) + Chr(0)
Edit. And comment out
Public Const OFN_ALLOWMULTISELECT = &H200&
If you want the user to only be able to select a single file.
-
WSJohnBF
AskWoody LoungerJuly 1, 2004 at 8:11 pm #846755(Edited by JohnBF on 01-Jul-04 14:11. )
Try the code here, but edit this line:
.lpstrFilter = “Image Files” + Chr(0) + “*.bmp;*.jpg;*.jpeg;*.jpe” + _
Chr(0) + “All Files (*.*)” + Chr(0) + “*.*” + Chr(0) + Chr(0)according to the target file type, such as all:
.lpstrFilter = “All Files (*.*)” + Chr(0) + “*.*” + Chr(0) + Chr(0)
Edit. And comment out
Public Const OFN_ALLOWMULTISELECT = &H200&
If you want the user to only be able to select a single file.
-
-
WSdane_walther
AskWoody Lounger
-
-
WSJohnBF
AskWoody LoungerJuly 1, 2004 at 5:52 pm #846707(Edited by JohnBF on 01-Jul-04 11:52. Outlook doesn’t support the Method. Available only in Ofiice 10+.)
Funny you should ask. This works in Excel but won’t run in Outlook, because the App doesn’t support the FileDialog method.
Sub TestBrowse4file()
MsgBox Browse4File
End SubPrivate Function Browse4File() As String
Dim dlgOpen As FileDialog
Dim varFile As Variant
Dim strReturnedPath As StringSet dlgOpen = Application.FileDialog(msoFileDialogFilePicker)
With dlgOpen
.AllowMultiSelect = False
.Show
For Each varFile In .SelectedItems
strReturnedPath = varFile
Next varFile
End With
Browse4File = strReturnedPath & CStr(varFile)End Function
I’m sure it needs more work.
-
WSHansV
AskWoody Lounger -
WSdane_walther
AskWoody LoungerJuly 2, 2004 at 11:08 am #847037WOW! So simple! I love it when it’s simple.
Now, just gotta parse the string out to the drive:pathfilename.extension…
Hans, I konw the answer to my question is “many years of experience,” so instead I’ll ask another; what would you recommend as a few (if there is not just one) of the best VBA reference books out there? This forum is so wonderful, but I feel like some of my questions are so simple I need a good reference to check before asking here.
thanks so much,
..dane -
WSHansV
AskWoody LoungerJuly 2, 2004 at 11:16 am #847043Perhaps others can answer your question about books (or do a search in this forum and the Word and Excel forums.) I don’t use books very often, I mostly rely on the online help, the object browser (F2 in the Visual Basic Editor) and on Internet (the Lounge, newsgroups, Knowledge Base, …)
-
WSHansV
AskWoody LoungerJuly 2, 2004 at 11:16 am #847044Perhaps others can answer your question about books (or do a search in this forum and the Word and Excel forums.) I don’t use books very often, I mostly rely on the online help, the object browser (F2 in the Visual Basic Editor) and on Internet (the Lounge, newsgroups, Knowledge Base, …)
-
-
WSdane_walther
AskWoody LoungerJuly 2, 2004 at 11:08 am #847038WOW! So simple! I love it when it’s simple.
Now, just gotta parse the string out to the drive:pathfilename.extension…
Hans, I konw the answer to my question is “many years of experience,” so instead I’ll ask another; what would you recommend as a few (if there is not just one) of the best VBA reference books out there? This forum is so wonderful, but I feel like some of my questions are so simple I need a good reference to check before asking here.
thanks so much,
..dane -
WSdane_walther
AskWoody LoungerJuly 2, 2004 at 4:29 pm #847150Hans,
[indent]
Word has Dialogs(wdDialogFileOpen) (use .Display to retrieve a filename without opening it, .Show to open a file)
Excel has Application.GetOpenFilename to retrieve a filename without opening it, and Application.Dialogs(xlDialogOpen).Show to open a file.
[/indent]
This method doesn’t seem to support a “default folder” to start out in… any way to do that?
thanks!
..dane -
WSHansV
AskWoody LoungerJuly 2, 2004 at 10:48 pm #847213Excel
You can use the old ChDrive and ChDir instructions to set the start folder:
Dim varResult As Variant
ChDrive “C”
ChDir “C:ExcelTest”
varResult = Application.GetOpenFilename
If varResult = False Then
MsgBox “No file selected.”
Else
MsgBox “You selected ” & varResult
End Ifor
ChDrive “C”
ChDir “C:ExcelTest”
Application.Dialogs(xlDialogOpen).ShowWord
With Application.Dialogs(wdDialogFileOpen)
.Name = “C:WordTest*.*”
If .Display = False Then
MsgBox “No file selected.”
Else
MsgBox “You selected ” & .Name
End If
End With -
WSjscher2000
AskWoody Lounger -
WSjscher2000
AskWoody Lounger
-
-
WSdane_walther
AskWoody LoungerJuly 2, 2004 at 4:29 pm #847151Hans,
[indent]
Word has Dialogs(wdDialogFileOpen) (use .Display to retrieve a filename without opening it, .Show to open a file)
Excel has Application.GetOpenFilename to retrieve a filename without opening it, and Application.Dialogs(xlDialogOpen).Show to open a file.
[/indent]
This method doesn’t seem to support a “default folder” to start out in… any way to do that?
thanks!
..dane
-
-
WSHansV
AskWoody Lounger
-
-
WSdane_walther
AskWoody Lounger
-
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
“kill switches” found in Chinese made power inverters
by
Alex5723
9 minutes ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
35 minutes ago -
Meet Gemini in Chrome
by
Alex5723
1 hour, 36 minutes ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
1 hour, 45 minutes ago -
Trump signs Take It Down Act
by
Alex5723
9 hours, 44 minutes ago -
Do you have a maintenance window?
by
Susan Bradley
58 minutes ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
1 hour ago -
Cox Communications and Charter Communications to merge
by
not so anon
13 hours, 3 minutes ago -
Help with WD usb driver on Windows 11
by
Tex265
18 hours, 13 minutes ago -
hibernate activation
by
e_belmont
21 hours, 59 minutes ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
1 day, 1 hour ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
1 day, 4 hours ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
1 day, 4 hours ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
57 minutes ago -
Out of band for Windows 10
by
Susan Bradley
1 day, 9 hours ago -
Giving UniGetUi a test run.
by
RetiredGeek
1 day, 16 hours ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
2 days ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
1 hour, 1 minute ago -
Auto Time Zone Adjustment
by
wadeer
2 days, 4 hours ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
2 days, 2 hours ago -
Manage your browsing experience with Edge
by
Mary Branscombe
1 hour, 48 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
19 hours, 21 minutes ago -
Hobbies — There’s free software for that!
by
Deanna McElveen
1 day, 1 hour ago -
Apps included with macOS
by
Will Fastie
23 hours, 37 minutes ago -
Xfinity home internet
by
MrJimPhelps
20 hours, 24 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
1 day, 21 hours ago -
Debian 12.11 released
by
Alex5723
3 days, 1 hour ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
3 days, 5 hours ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
2 days, 8 hours ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
1 hour, 12 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.