วันพฤหัสบดีที่ 3 ธันวาคม พ.ศ. 2558

Excel : VBA การใช้คำสั่ง FileDialog เพื่อเลือกไฟล์ หรือ Folder

       นำ Code ตัวอย่างไปใช้ได้เลย

Code :
' ต้องการเลือก Folder
Sub SelectFolder()
Dim PathFolder As String
With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Select a Folder"
    .AllowMultiSelect = False
    .InitialFileName = "" '<~~ The start folder path for the file picker.
    If .Show = -1 Then 'GoTo NextCode
        If Right(.SelectedItems(1), 1) = "\" Then
            PathFolder = .SelectedItems(1)
        Else
            PathFolder = .SelectedItems(1) & "\"
        End If
        Range("B3").Select
        ActiveCell.FormulaR1C1 = PathFolder
    End If
End With
End Sub

' กรณีต้องการเลือกไฟล์
With Application.FileDialog(msoFileDialogFilePicker)

0 ความคิดเห็น:

แสดงความคิดเห็น

 
Copyright © . DataJeda Computer Basic - Posts · Comments
Theme Template by DataJeda.com · Powered by DataJeda.com