0

So I am looking to automatically bookmark a PDF. I am having success executing the first few loops, but then it glitches after and does not bookmark the correct location. As well, I would like to know if there are better alternatives to the ^f and ^b. Here is the code I have so far:


    ActiveWorkbook.FollowHyperlink "C:\Test.pdf"

    Dim searchString As String
    'Create loop using variable i
    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 ``` 


Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • That beeing said: There are always better alternatives to `SendKeys`. `SendKeys` is always the worst solution to automate something, because it is not reliable at all. Any user interaction (like a simple click) and the complete code glitches. • So always use an API if you can. Actually Foxit has one: [API Reference for Application Communication.pdf](http://cdn01.foxitsoftware.com/pub/foxit/manual/phantom/en_us/API%20Reference%20for%20Application%20Communication.pdf). Search the Foxit website for more information. – Pᴇʜ Nov 26 '19 at 07:22
  • Note: If you ask on Stack Overflow make sure your post has a question that meets the SO criteria (see [ask]). Your post is very broad and asks more for an opinion, than a precise question, which actually makes it off-topic. – Pᴇʜ Nov 26 '19 at 07:24

0 Answers0