使用 Excel VBA 从 PDF 中检索出现唯一关键字的整行文本

问题描述 投票:0回答:0

在 Excel 中,我需要打开一个现有的 pdf 文件,搜索一个唯一的文本字符串,然后将找到该字符串的整行复制到 Excel 工作表中。

我无法访问 Acrobat 的 Pro 版本,所以我使用 VBA 通过 FollowHyperlink 方法打开 PDF 文件,并通过使用 Sendkeys 与 PDF 查找框对话成功找到唯一的文本字符串(是的,我知道它有点不稳定,但这是一个低容量的活动),但我无法弄清楚如何检索找到唯一文本的整行文本,以便我可以将其添加到 Excel 工作表中。到目前为止我的代码是:

         PDF_path = TempFolder & SA_File_Name ' complete path to rpt
    
        'Open the pdf file
        ThisWorkbook.FollowHyperlink PDF_path
    
        'Wait time for a couple of seconds for the PDF file to fully load
        Application.Wait (Now + TimeValue("0:00:02"))
    
        '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
    
        'Your search string - case-insensitive, as in actual PDF search
        PDFSearchString = "Security Audits"
        'Type the search string in the find box that opens
        SendKeys PDFSearchString, True
        'Hit enter to perform the search
        SendKeys "{Enter}", True

这里是我想要获取整行并将其复制到工作表的地方。

vba pdf adobe acrobat
© www.soinside.com 2019 - 2024. All rights reserved.