티스토리 뷰

Excel VBA 지정한 폴더 안에있는 파일명 출력하는 예제



Sub Main()

    dirName = "c:\practice\"

    Call printFileList(dirName)


End Sub


Sub printFileList(folderName)

    Dim objFSO As Object

    Dim objFolder As Object

    Dim objFile As Object

    Dim i As Integer

    

    'Create an instance of the FileSystemObject

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    'Get the folder object

    Set objFolder = objFSO.GetFolder(folderName)

    i = 1

    'loops through each file in the directory and prints their names and path

    For Each objFile In objFolder.Files

        'print file name

        Cells(i + 1, 1) = objFile.Name

        'print file path

        Cells(i + 1, 2) = objFile.Path

        i = i + 1

    Next objFile


End Sub





이렇게 출력된다.


end.




공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함