FileOpen - FileSave
The routines to open or save files are very similar. Fill the structure and call the function.
Copy the following code into a second module:
Public Const strVersion As String = "V1.0" 'open and save dialogs
Public Const strMakro As String = "Common Dialogs Open/Save"
CDlgInitialize 0& 'no owner
If CDlgOpenDlg(0&) Then MsgBox ofn.lpstrFile 'no owner
If CDlgSaveDlg(0&, "c:\dummy.txt") Then MsgBox ofn.lpstrFile 'no owner
Public Function Trim0(sName As String) As String
'if there is one or more trailing /0, trim the string
If InStr(sName, Chr$(0)) Then
Trim0 = Mid$(sName, 1, InStr(sName, Chr$(0)) - 1)
Trim0 = sName
A parent handle is not needed to call 'FileOpen' or 'FileSave', but may be supplied.
Since the structure needed to the open/save dialogs is very similar, most of the structure is filled in the function 'DlgInitialize' (as in the example in Charles Petzold's book).
The result of a call to 'FileOpen' looks like this (depending on operating system):
... and FileSave: