MS Access VBA从文件夹中查找图像

时间:2017-01-04 08:43:38

标签: vba ms-access access-vba

我正在使用此页面中的以下代码:

MS Access VBA lookup image file names from table, search for them and copy them

Public Sub listImages(folderPath As String)

    'define variables
    Dim fso As Object
    Dim objFolder As Object
    Dim objFolders As Object
    Dim objF As Object
    Dim objFile As Object
    Dim objFiles As Object
    Dim strFileName As String
    Dim strFilePath As String
    Dim myList As String

    'set file system object
    Set fso = CreateObject("Scripting.FileSystemObject")

    'set folder object
    Set objFolder = fso.GetFolder(folderPath)

    'set files
    Set objFiles = objFolder.files
    Set objFolders = objFolder.subfolders

    'list all images in folder
    For Each objFile In objFiles

        If Right(objFile.Name, 4) = ".jpg" Then
            strFileName = objFile.Name
            strFilePath = objFile.Path
            myList = myList & strFileName & " - " & strFilePath & vbNewLine
        End If

    Next

    'go through all subflders
    For Each objF In objFolders

        'call same procedure for each subfolder
        Call listImages(objF.Path)

     Next

     Debug.Print myList

     Set objFolder = Nothing
     set objFolders = Nothing
     Set objFile = Nothing
     set objF = Nothing
     Set fso = Nothing


End Sub

但是,它只返回每个文件夹和子文件夹中的第一个图像。如何修改它以显示每个文件夹\子文件夹中的所有图像?

感谢。

0 个答案:

没有答案