循环遍历PDF文件的文件夹

时间:2015-06-30 17:49:11

标签: excel vba pdf

我想循环浏览PDF文件的文件夹,并将文件插入word文档的相应文本框中。

我无法在网上找到它,但我试图在循环浏览excel文件的文件夹时对我的代码进行建模......我还没有试图让它插入PDF但我正在尝试首先解决这个问题。顺便说一句,如果有帮助,我有Adobe Reader而不是Adobe Professional。

我调试了代码,错误发生在Set fromPDF = AcroExch.PDDoc.Open(sPath & sFile) ...

任何帮助都将不胜感激。

Sub UseTextBox()

Dim reportDoc As Object
Dim str As String
Dim tag As String
Dim pdfName As String

Set reportDoc = ActiveDocument
MsgBox reportDoc

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False


'match PDF to figure and insert
Set SelectFolder = Application.FileDialog(msoFileDialogFolderPicker)
    With SelectFolder
        .Title = "Select Directory"
        .AllowMultiSelect = False
        If .Show <> -1 Then GoTo ResetSettings
        sPath = .SelectedItems(1) & "\"
    End With



sFile = Dir(sPath & "*pdf")
Do While sFile <> ""
    Set fromPDF = AcroExch.PDDoc.Open(sPath & sFile)
    pdfName = sFile


For Each objShape In reportDoc.Shapes
    If objShape.Type = msoTextBox Then
        str = objShape.TextFrame.TextRange.Text
        If InStr(str, "(") > 0 Then

            tag = BetweenParentheses(objShape.TextFrame.TextRange)
            MsgBox tag
        End If
    End If
Next objShape
sFile = Dir
Loop

ResetSettings:
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False



End Sub

1 个答案:

答案 0 :(得分:0)

您在哪里创建AcroExch对象?我想这可能是你的问题。

您可能需要以下内容:

Set MyObject = CreateObject("AcroExch.PDDoc")