简体   繁体   中英

Import PDF text with Font color

I have a table of values stored in PDF format where the words are color coded eg Red color is bad, Green is good.

I found code to import PDF values into Excel but not the font color, without which, I cannot identify the status (good/bad) of the value.

Can I have the values the same font color?

Sub importPDFTable(inputFileName As String, inputWsName As String)

Dim wdDoc As Object
Dim wdFileName As Variant
Dim wrd As Object
Dim inputWs As Worksheet

    Set inputWs = Sheets(inputWsName)
    inputWs.UsedRange.ClearContents

    Set wrd = CreateObject("Word.Application")
    Debug.Print wdFileName
    Set wdDoc = wrd.Documents.Open(inputFileName) 'open PDF file in Word
    wrd.Visible = False

    wrd.Selection.WholeStory
    wrd.Selection.Copy
    inputWs.Range("A1").PasteSpecial xlPasteValues

    Set wdDoc = Nothing
    wrd.Quit
    Set wrd = Nothing
End Sub

Try this code: I have changed the line where you are pasting the code.

Sub importPDFTable(inputFileName As String, inputWsName As String)

Dim wdDoc As Object
Dim wdFileName As Variant
Dim wrd As Object
Dim inputWs As Worksheet

    Set inputWs = Sheets(inputWsName)
    inputWs.UsedRange.ClearContents

    Set wrd = CreateObject("Word.Application")
    Debug.Print wdFileName
    Set wdDoc = wrd.Documents.Open(inputFileName) 'open PDF file in Word
    wrd.Visible = False

    wrd.Selection.WholeStory
    wrd.Selection.Copy

    inputWs.Range("A1").Select
    ActiveSheet.PasteSpecial Format:="HTML"

    Set wdDoc = Nothing
    wrd.Quit
    Set wrd = Nothing
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM