【发布时间】:2017-03-18 04:50:30
【问题描述】:
我在尝试自动执行 PDF 字符串搜索并在 Excel 中记录结果时收到此错误,“Microsoft Excel 正在等待另一个应用程序完成 OLE 操作”。对于某些 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
【问题讨论】:
-
请以正确的格式发布您的代码。
-
对此感到抱歉...我对这个网站很陌生。正在为html而苦苦挣扎