I need to use the Common Dialog box, but I'm having trouble getting started.
Bear with me as this is new ground for me...
First, I get an error trying to declare these functions -- compile error:
User-defined type not defined - am I missing a reference? which one?
Private Declare Function GetOpenFileName _
Lib "COMDLG32.DLL" Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName _
Lib "COMDLG32.DLL" Alias "GetSaveFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetActiveWindow _
Lib "user32" () As Long
Then, how do I use this code (below)? Do I simply create a
cmdGetFileFromAPI_Click command button on my form?
Do I need anything else in order to launch the Common Dialog Box?
Sub GetFileFromAPI()
Dim OFN As OPENFILENAME
With OFN
.lStructSize = Len(OFN) ' Size of structure.
.nMaxFile = 260 ' Size of buffer.
' Create buffer.
.lpstrFile = String(.nMaxFile - 1, 0)
Ret = GetOpenFileName(OFN) ' Call function.
If Ret <> 0 Then ' Non-zero is success.
' Find first null char.
n = InStr(.lpstrFile, vbNullChar)
' Return what's before it.
MsgBox Left(.lpstrFile, n - 1)
End If
End With
End Sub