Thank you for this method. But comparing with the UserAccounts.CommonDialog method, your method is rather cumbersome construction. It requires a lot of excessive statements.
I expected some approach built in Windows 7.
However, it does work.
If it is a type which uses Excel, there is also a little easy construction.
All the samples which work on Win7 which I have are sent.
The method of using "MSComDlg.CommonDialog" works on a 32-bit command prompt.
And if VB6 is not installed, vb6controls.reg needs to be installed.
OpenFileDialog2.zip 3.7 KB
Thank you very much for multiple methods you have sent me. I will certainly use some of them.
I found some code that uses Microsoft Word to call a file dialog. In our environment, everyone has MS Office installed. It works well on Windows 7.
Function fBrowseForFile(sBrowsePath) 'sBrowsePath is the directory to start in.
' This function opens a common file browsing dialog box
' pointed at the local C:\ drive. When a file is selected
' this function will return the path and filename in a string.
' If cancel is clicked or the browse window is closed without
' a file being selected, the function returns an empty string.
Dim sBrowseFilter, oBrowseDialog
'set the type of dialog box you want to use
'1 = Open
'2 = SaveAs
'3 = File Picker
'4 = Folder Picker
Const msoFileDialogOpen = 1
Set objWord = CreateObject("Word.Application")
.Title = "Select the file to process"
.AllowMultiSelect = False
.Filters.Add "All Files", "*.*"
If .Show = -1 Then
For Each objReturnFile In .SelectedItems
Set objFile = objFso.GetFile(objReturnFile)
fBrowseForFile = objFile.Path
I personally like visual studio for these kinds of things, makes life a lot easier. But just my personal preference.
Dim openfiledialog1 As New OpenFileDialog
Dim result As DialogResult = openfiledialog1.ShowDialog()
OpenFileDialog openFileDialog1= new OpenFileDialog;
DialogResult result = openFileDialog1.ShowDialog();
I also use vb.net for this. It's super easy.
1. Add the open file dialog object to the form.
2. Use code something like this:
Main_Form.dlg_open.Title = title
Main_Form.dlg_open.FileName = ""
file = ""
if Main_Form.dlg_open.ShowDialog() = dialogresult.OK then
file = Main_Form.dlg_open.FileName
3. The result is that 'file' captures the filename of the file to open.
Oh and by the way the same code works equally well in XP or W7.