2016年6月10日 星期五

[VBA] A macro for copying the text from pdf to excel with Adobe Reader ONLY

Sub pdf2exl()
    Dim starDir As String, PDFPath As String, READERPath As String

    'Starting path for user selecting pdf files
    startDir = "C:\testing\"
    ChDir startDir
    PDFPath = Application.GetOpenFilename(filefilter:="PDF file (*.pdf), *.pdf")
    If UCase(PDFPath) = "FALSE" Then
        Exit Sub
    End If

    'Please change to your own Adobe Reader installation path
    READERPath = "C:\Program Files (x86)\Adobe\Acrobat Reader\AcroRd32.exe "
    Shell READERPath & PDFPath, vbNormalFocus: DoEvents
    Application.Wait Now + TimeValue("00:00:2")
    SendKeys "^a", True
    Application.Wait Now + TimeValue("00:00:2")
    SendKeys "^c"
    Application.Wait Now + TimeValue("00:00:2")
    SendKeys "%{F4}", True
    Application.Wait Now + TimeValue("00:00:2")
    
    'Paste in Sheet1
    Worksheets("Sheet1").Activate
    Sheet1.Cells.Clear
    Sheet1.Paste Sheet1.Range("A1")
End Sub

沒有留言:

張貼留言