我有这个VBA代码,可以在计算机上搜索PDF文件。这是代码:
Option Explicit
Sub FindTextInPDF()
Dim TextToFind As String
Dim PDFPath As String
Dim App As Object
Dim AVDoc As Object
Dim DS As Worksheet
Dim SS As Worksheet
Set DS = Sheets("Report")
Set SS = Sheets("Search Index")
Dim sslastrow As Long
Dim dslastrow As Long
Dim b As Integer
Dim J As Integer
With SS
sslastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
End With
With DS
dslastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For b = 2 To dslastrow
PDFPath = "C:\Users\desposito\Documents\Temp\" &
Sheets("Report").Range("E" & b).Value & Sheets("Report").Range("B" &
b).Value & ".pdf"
If Dir(PDFPath) = "" Then
GoTo nextb
End If
If LCase(Right(PDFPath, 3)) <> "pdf" Then
GoTo nextb
End If
On Error Resume Next
Set App = CreateObject("AcroExch.App")
If Err.Number <> 0 Then
Set App = Nothing
GoTo nextb
End If
Set AVDoc = CreateObject("AcroExch.AVDoc")
If Err.Number <> 0 Then
Set AVDoc = Nothing
Set App = Nothing
GoTo nextb
End If
On Error GoTo 0
If AVDoc.Open(PDFPath, "") = True Then
AVDoc.BringToFront
Else
App.Exit
Set AVDoc = Nothing
Set App = Nothing
GoTo nextb
End If
For J = 2 To sslastrow
TextToFind = SS.Range("B" & J).Value
If AVDoc.FindText(TextToFind, False, False, True) = False Then
GoTo NextJ
Else:
DS.Range("Q" & b).Value = DS.Range("Q" & b).Value & TextToFind & ";"
& " "
End If
NextJ:
Next
AVDoc.Close True
App.Exit
Set AVDoc = Nothing
Set App = Nothing
nextb:
Next
End Sub
但是,每隔100个文件,我会收到此通知:
“阅读器已完成文档搜索。找不到匹配项。”
我所要做的就是按Enter键,然后代码运行另外10-30分钟,然后再次收到通知。似乎是在搜索文档的中间,这是代码的这一部分:
For J = 2 To sslastrow
TextToFind = SS.Range("B" & J).Value
If AVDoc.FindText(TextToFind, False, False, True) = False Then
GoTo NextJ
Else:
DS.Range("Q" & b).Value = DS.Range("Q" & b).Value & TextToFind & ";"
& " "
End If
NextJ:
我研究了在acrobat中禁用屏幕警报,但是看起来我无法做到这一点。