0

所以我想做的是浏览一个 PDF,发送键 CTRL+F 以从 C 列中查找一串文本并突出显示第一个结果,然后是另一个发送键来为单词添加书签。当我尝试循环时,前 3 个成功,但失败了。我正在使用 Foxit,我似乎找不到更好的替代发送代码,所以我也愿意接受建议。我查看了 API Foxit 指南,并没有找到任何特定于我需要的代码。

Sub BookmarkingWithSendKeys()

ActiveWorkbook.FollowHyperlink "C:\Test.pdf"

    Dim searchString As String
    'Create loop using variable i, searching PDF in column C (3 if you do R1C1).
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
    For I = 1 To FinalRow

    searchString = Cells(I, 3).Value

    'Send "CTRL + F" keys to the opened PDF to invoke find within that file
    'The second argument "true" implies that Excel will wait for the keys to be processed before returning control to the macro.
    SendKeys "^f", True

    'Type the search string in the find box that opens
    SendKeys searchString, True

    'Hit enter to perform the search
    SendKeys "{Enter}", True

    'Bookmark highlighted text
    SendKeys "^b", True

    'Hit enter to perform the bookmark
    SendKeys "{Enter}", True
        Next I

    Application.DisplayAlerts = True

End Sub
4

0 回答 0