我收到此错误," Microsoft Excel正在等待另一个应用程序完成OLE操作"尝试自动化PDF字符串搜索并在excel中记录结果时。对于某些PDF,此错误不会弹出。我认为这是由于较少优化的PDF在逐页索引时花费较长时间搜索字符串。
更确切地说,我有一张包含两张纸的工作簿。一个包含PDF文件名列表,另一个包含我要搜索的单词列表。从文件列表中,宏将打开每个PDF文件,并从单词列表中取出每个单词并执行字符串搜索。如果找到它,它将使用文件名和找到的字符串在同一工作簿中的新工作表中记录每个发现。
以下是我挣扎的代码。欢迎任何帮助。
Public Sub SearchWords()
'variables
Dim ps As Range
Dim fs As Range
Dim PList As Range
Dim FList As Range
Dim PLRow As Long
Dim FLRow As Long
Dim Tracker As Worksheet
Dim gapp As Object
Dim gAvDoc As Object
Dim gPDFPath As String
Dim sText As String 'String to search for
FLRow = ActiveWorkbook.Sheets("List Files").Range("B1").End(xlDown).Row
PLRow = ActiveWorkbook.Sheets("Prohibited Words").Range("A1").End(xlDown).Row
Set PList = ActiveWorkbook.Sheets("Prohibited Words").Range("A2:A" & PLRow)
Set FList = ActiveWorkbook.Sheets("List Files").Range("B2:B" & FLRow)
Set Tracker = ActiveWorkbook.Sheets("Tracker")
'For each PDF file list in Excel Range
For Each fs In FList
'Initialize Acrobat by creating App object
Set gapp = CreateObject("AcroExch.App")
'Set AVDoc object
Set gAvDoc = CreateObject("AcroExch.AVDoc")
'Set PDF file path to open in PDF
gPDFPath = fs.Cells.Value
' open the PDF
If gAvDoc.Open(gPDFPath, "") = True Then
'Bring the PDF to front
gAvDoc.BringToFront
'For each word list in the range
For Each ps In PList
'Assign String to search
sText = ps.Cells.Value
'This is where the error is appearing
If gAvDoc.FindText(sText, False, True, False) = True Then
'Record findings
Tracker.Range("A1").End(xlDown).Offset(1, 0) = fs.Cells.Offset(0, -1).Value
Tracker.Range("B1").End(xlDown).Offset(1, 0) = ps.Cells.Value
End If
Next
End If
'Message to display once the search is over for a particular PDF
MsgBox (fs.Cells.Offset(0, -1).Value & " assignment complete")
Next
gAvDoc.Close True
gapp.Exit
set gAVDoc = Nothing
set gapp = Nothing
End Sub
答案 0 :(得分:0)
我现在找到了这个问题的答案。
我正在使用Acrobat Pro,每当我打开PDF文件时,由于受保护的视图设置,它会打开但功能有限。如果我禁用此功能或单击启用所有功能并保存对PDF文件的更改,则VBA宏将顺利运行。
这很有趣,我正在回答我自己的问题。