Private Sub Command1_Click()
On Error Resume Next
With CommonDialog1
.CancelError = True
.Filter = "TextFile(*.txt)|*.txt|AllFile(*.*)|*.*"
.Flags = cdlOFNAllowMultiselect Or cdlOFNLongNames Or cdlOFNHideReadOnly
.ShowOpen
MsgBox "Your selection are " + .FileName, 64, "Select Files"
End With
End Sub
对于flags可参考一下说明进行设置:
常数 值 描述
1、cdlOFNAllowMultiselect &H200 它指定文件名列表框允许多重选择。 运行时,通过按 SHIFT 键以及使用 UP ARROW 和 DOWN ARROW 键可选择多个文件。作完此操作后,FileName 属性就返回一个包含全部所选文件名的字符串。串中各文件名用空格隔开。
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
Private Const CB_FINDSTRING = &H14C
Private Const CB_FINDSTRINGEXACT = &H158
Private Const LB_FINDSTRING = &H18F
Private Const EM_SETREADONLY = &HCF
Private Const SND_RESOURCE = &H40004
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found
'系统全局函数========================================================================
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 Sub Command1_Click()
Dim fName As String, OfName As OPENFILENAME