นำ 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)
Home » VBA » Excel : VBA การใช้คำสั่ง FileDialog เพื่อเลือกไฟล์ หรือ Folder
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
0 ความคิดเห็น:
แสดงความคิดเห็น