Common Dialog...

cmancuso1

New Member
Joined
Aug 27, 2002
Messages
3
I am trying to add a common dialog for the browse function. I would like to add a command button to a form that will open the browse com dlg so the user may select a graphic file to import.

Any help will be greatly appreciated.

THX
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Best I can understand, reference will need to be added, since Commmon Dialog is not standard equipment.

Try Comdlg32.ocx, Microsoft Common Dialog Control.

Good Luck,
Steve

P.S. Once you set the Reference, and add the control to the Toolbox, CommonDialog will be found in Object Browswer; select it and press F1 (Help) for information on the control.

The Example will be confusing for VBA programmers; the default names of controls are strictly VB, and there is no (imho) way to construct an Option Button array in VBA.
This message was edited by stevebausch on 2002-09-03 07:17
 
Upvote 0
Using the cmdlg can be useful for Filtering as the getopen file VBA doesn't offer this option, so unless you are looking to do something withit that can't be done using STD VBA Getopenfilename then Stick to GetOpenfilename, otherwise try this;
Note: How it builds the Type structure up that you will need for the API call.
There are also a number of other properties and const that you can use.

<pre/>
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" ( _
pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Sub Cmdlg_Open()
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String

OpenFile.lStructSize = Len(OpenFile)
sFilter = "my XlFiles (*.xls)" & Chr(0) & "*.xls" & Chr(0)
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = "C:"
OpenFile.lpstrTitle = "Use the Cmdlg API and NOT Ocx"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "The User pressed the Cancel Button"
Else
MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)
Workbooks.Open Trim(OpenFile.lpstrFile)
End If

End Sub
</pre>
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top