Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access Microsoft Access 2010打开目录中的所有文件_Ms Access_Vba - Fatal编程技术网

Ms access Microsoft Access 2010打开目录中的所有文件

Ms access Microsoft Access 2010打开目录中的所有文件,ms-access,vba,Ms Access,Vba,我正在创建MS Access 2010数据库。我正在使用API来执行以前版本的MS Access中的公共对话框控件所做的操作,以打开目录并选择文件。我的客户希望我能够在用户单击文件夹时打开目录中的所有文件(这样用户就不会单击文件,而只单击文件夹)。在使用API弹出的公共对话框控件中单击文件夹时,我找不到偶数触发 有谁能告诉我,在MS ACCESS 2010中使用通用对话框控件的API时,如何打开目录中的所有文件(它们将是.pdf文件) 我使用的API调用如下:使用Microsoft.Script

我正在创建MS Access 2010数据库。我正在使用API来执行以前版本的MS Access中的公共对话框控件所做的操作,以打开目录并选择文件。我的客户希望我能够在用户单击文件夹时打开目录中的所有文件(这样用户就不会单击文件,而只单击文件夹)。在使用API弹出的公共对话框控件中单击文件夹时,我找不到偶数触发

有谁能告诉我,在MS ACCESS 2010中使用通用对话框控件的API时,如何打开目录中的所有文件(它们将是.pdf文件)


我使用的API调用如下:

使用Microsoft.Scripting.Runtime中的FileSystemObject(必须添加对项目的引用)。 以下子项向集合中添加给定文件夹中所有pdf文件的字符串名称。 从对话框中获取文件夹路径(使用文件夹拾取选项,而不是文件拾取)


这对我来说非常有效。。。它将提示对话框选择文件夹并打开.pdf文件。它还将列出表1中的所有文件

    Option Compare Database
'函数选择文件所在的文件夹:

运行Open_List_Files()宏,您就可以开始了!:)

    Option Compare Database
    Function ChooseFolder() As String


        Dim fldr As FileDialog
        Dim sItem As String

        Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
        With fldr
            .Title = "Select a Folder"
            .AllowMultiSelect = False
            .InitialFileName = strPath
            If .Show <> -1 Then GoTo NextCode
            sItem = .SelectedItems(1)
        End With

    NextCode:
        ChooseFolder = sItem
        Set fldr = Nothing

    End Function
    Sub Open_List_Files()


    'Declare the variables
    Dim objFSO As Scripting.FileSystemObject
    Dim objFolder, objTopFolder As Scripting.Folder
    Dim strTopFolderName As String, ProjectF As String
    Dim i As Long

    ' call the function to select the folder
    Call Módulo1.ChooseFolder

    'Create an instance of the FileSystemObject
    Set objFSO = CreateObject("Scripting.FileSystemObject")


    'Get the top folder
    Set objTopFolder = objFSO.GetFolder(ChooseFolder)

    'Call the RecursiveFolder routine
    Call RecursiveFolder(objTopFolder, True)


End Sub

Sub RecursiveFolder(objFolder As Scripting.Folder, IncludeSubFolders As Boolean)

    'Declare the variables
    Dim objFile As Object
    Dim objSubFolder As Scripting.Folder
    Dim DBStr, filepath As String

    'Loop through each file in the folder
    For Each objFile In objFolder.Files
    On Error Resume Next

    If InStr(objFile.Name, ".pdf") Then

    DBStr = "INSERT INTO Table1 ([File Name]) " & _
            " VALUES (" & _
            "'" & objFile.Name & "', " & "');"

    CurrentDb.Execute DBStr

    'open the file
    Application.FollowHyperlink objFile

    End If

    Next objFile

    'Loop through files in the subfolders
    If IncludeSubFolders Then
        For Each objSubFolder In objFolder.SubFolders
            Call RecursiveFolder(objSubFolder, True)
        Next objSubFolder
    End If


End Sub