Option Explicit
Public Function GetFiles(Optional ByVal sTitle As String = "Open files...") As String
Dim sFilenames As String
Dim cdlOpen As Object
On Error GoTo ProcError
' Get the desired name using the common dialog
Set cdlOpen = CreateObject("MSComDlg.CommonDialog")
' set up the file open dialog file types
With cdlOpen
' setting CancelError means the control will
' raise an error if the user clicks Cancel
.CancelError = True
.Filter = "VB Files *.frm;*.bas;*.cls;*.res;*.ctl;*.dob;*.pag;*.dsr)|*.frm;*.bas;*.cls;*.res;*.ctl;*.dob;*.pag;*.dsr|Form Files *.frm)|*.*.frm|Basic Files *.bas)|*.bas|All Files *.*)|*.*"
.FilterIndex = 1
.DialogTitle = sTitle
.MaxFileSize = &H7FFF ' 32KB filename buffer
' same as .Flags = cdlOFNHideReadOnly Or cdlOFNPathMustExist Or cdlOFNLongNames Or cdlOFNAllowMultiselect or cdlOFNExplorer
.Flags = &H4 Or &H800 Or &H40000 Or &H200 Or &H80000
.ShowOpen
sFilenames = .Filename
End With
ProcExit:
GetFiles = sFilenames
Set cdlOpen = Nothing
Exit Function
ProcError:
If Err.Number = &H7FF3 Then Resume Next 'Cancel selected - Ignore
MsgBox Err.Description & "(" & Err.Number & ")", vbExclamation, "Open error"
sFilenames = ""
Resume ProcExit
End Function
'contoh penggunaan fungsi di atas
Private Sub Command1_Click()
Dim Filename As Variant
Filename = Split(GetFiles, Chr(0))
For i = 1 To UBound(Filename)
List1.AddItem Filename(0) & "\" & Filename(i)
Next
End Sub
Tuesday, May 29, 2012
Memilih Lebih dari Satu File Pada Dialog Open - VB6 Code
Labels:
File-And-Folder