VB6 Common Dialog

'----------------------------
'Class CommonDialog
'Member of MSComDlg
'----------------------------

Private Sub Command1_Click()
ShowOpenFile
End Sub

Private Sub ShowOpenFile()

Dim gLastClDir As String, FilePath As String, TempDir As String
gLastClDir = App.Path  '"C:wgscd"
On Error GoTo ErrHandler
With cdlOpendb
    .CancelError = True
    .FileName = ""
    .InitDir = gLastClDir
    .DefaultExt = ".cl2"
    .DialogTitle = "Open File for Import"
    .Filter = "COMMLINK Files (*.cl2)|*.cl2"
    .FilterIndex = 1
    '.Flags = cdlOFNPathMustExist + cdlOFNHideReadOnly + cdlOFNExtensionDifferent + cdlOFNFileMustExist
    .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNCreatePrompt
    .ShowOpen
End With

FilePath = cdlOpendb.FileName
MsgBox FilePath

' On Error Resume Next
' TempDir = Left(FilePath, InStr(FilePath, ".")) & " em33"
' MkDir TempDir
'Kill TempDir & "*.*"
ExitOut:
ErrHandler:
'User pressed the Cancel button from the Open Dialog
End Sub

原文地址:https://www.cnblogs.com/wgscd/p/5773400.html