Page 1 of 1

Code VB เปิดโฟลเดอร์เป้าหมาย

Posted: Sun Jun 09, 2024 9:40 pm
by tigerwit
จากไฟล์ที่แนบมา
ทุกครั้งที่คลิกปุ่มเปิดโฟลเดอร์ ต้องการให้ไปยังโฟลเดอร์เป้าหมายที่อยู่ใน Drive C:\โฟลเดอร์เป้าหมาย
(ชื่อโฟลเดอร์เป้าหมาย จะอยู่ที่ เซล A9)
จะปรับโค๊ดอย่างไรครับ

Code: Select all

Sub GetFile()
Dim sFullPath As String
Dim tFolderPath As String
tFolderPath = Range("A9").Value
sFullPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx),*.xlsx", _
                    Title:="Please select an Excel file")
End Sub

Re: Code VB เปิดโฟลเดอร์เป้าหมาย

Posted: Sun Jun 09, 2024 10:24 pm
by snasui
:D ตัวอย่าง Code ครับ

Code: Select all

Sub GetFile()
    Dim sFullPath As String
    Dim tFolderPath As String
    tFolderPath = Range("A9").Value
    ChDir (tFolderPath)
    sFullPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsx),*.xlsx", _
                        Title:="Please select an Excel file")
End Sub