Reputation: 11
I am new to vba
and I have been trying to open a PDF file with MS word
2016 in order to copy the data and populate cells in Excel
, I have been able to open the PDF and copy the data but I have found it tricky to get the data I need and to populate the cells in Excel
. I was wondering if this was possible to code in VBA via excel
.
thanks
Upvotes: 1
Views: 11403
Reputation: 4704
This solution requires a reference to the Word library to be set in Excel (Tools,references)
Sub test()
Dim s As String
Dim t As Excel.Range
s = "\\my path\my file.pdf"
Dim wd As New Word.Application
Dim mydoc As Word.Document
Set mydoc = Word.Documents.Open(Filename:=s, Format:="PDF Files", ConfirmConversions:=False)
Dim wr As Word.Range
Set wr = mydoc.Paragraphs(1).Range
wr.WholeStory
Set t = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
wr.Copy
t.PasteSpecial xlPasteValues
mydoc.Close False
wd.Quit
End Sub
Upvotes: 4