วันศุกร์ที่ 26 มกราคม พ.ศ. 2561

VBA สร้าง Folder


       แนะนำโค๊ดสร้าง Folder ด้วย VBA ใช้โค๊ดเพียง 4 บรรทัด ก็สร้าง Folder ได้แล้ว ครับ

ตัวอย่างโค๊ด

Set fso = CreateObject("Scripting.filesystemobject") ' สร้าง Object fso
    If Not fso.folderExists(fol) Then ' ตรวจสอบว่ามี Folder หรือยัง
        fso.CreateFolder (fol) ' ทำการสร้าง
    End If


ลองเขียนโค๊ด

Sub CreateFolder()
    Dim fso
    Dim fol As String
    Dim FolderName As String
    FolderName = Sheets("Sheet1").Range("B2").Value
    fol = ThisWorkbook.Path & "\" & FolderName
    Set fso = CreateObject("Scripting.filesystemobject")
    If Not fso.folderExists(fol) Then
        fso.CreateFolder (fol)
    End If
End Sub

Download >>>> Source Code

Good Luck

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

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

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