Extract data from PDF to Word using Excel VBA

Shodi

Board Regular
Joined
May 24, 2016
Messages
53
Hi everyone, Wishing you all a belated very happy new year.

I am using the below code to extract data from PDF to Excel. I have only reached partway through the process - opening the PDF as word Doc.

I have the code to copy and paste the data in excel from the converted word doc but the problem I face is that the data from the PDF when converted to Word looks like what I have pasted below.

"%PDF-1.3
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Filter /FlateDecode /Length 3393>>
stream
xœ\ÛrÛ8}÷Wà1(c)ZCxÏ›bˉ&‰â••LmU^›Ž5-E‡-&å¿_€$Ø µSµã
Ð
Ý
Ràò×£IFþœ1/2ßÙ')eŒlîÉbsö›Ä Âä?' B'e4g$ËSZäö‰Ì-œ\Ö俺5gÐ\ ÙLveR²¹#o>|ý3/4X¯3/4,VòõŠ|Z¬çŸçoÉæŸ3/4ÁìJÂî"‹i*"HmÕùÅGÙje4ky$K8x
úñf³&\ù·V÷ÜéžrÀ²e"Q-÷-oªŠ4Ç]%G#~1/4!*äÇ[Rîïdw1(c)ïɧª)w%94Uùrl^Ém}W!/F-dèÌÿo~qÊ#tAr@‹1/4i''Ò(tm)iÁUvä†8õrÄ,Ò&Ô÷
t1/2Ñþ·Læ/"ýF'‚8"éïâúa1/2"ý( ¡3ËÕá'cfº¶K"áÜbã
ì'ˆæ(c)ÉîÓgƲ"(tm)Ô"ÿð...ÃÕŠ"f¯")û>ãqFc)a-Q(tm)NN"œœgÊ}S'{Y[Ð,×µŒf...U+Yeq¸6¥œ‡kåßEÐoÚ†..........................................


Can anyone tell me why this is and how to get around this.
I am using MS Word 2010 and MS Excel 2010
Thanks in advance.


VBA Code:
Sub PDF_To_Word()

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")

Dim fso As New FileSystemObject
Dim fo As Folder
Dim f As File
Dim wordApp As New Word.Application
Dim wordDoc As Word.Document
Dim PDF_path As String
Dim Word_path As String

PDF_path = sh.Range("F4").Value
Word_path = sh.Range("F5").Value

wordApp.Visible = True

Set fo = fso.GetFolder(PDF_path)

For Each f In fo.Files
    Set wordDoc = wordApp.Documents.Open(f.Path)
        wordDoc.SaveAs2 (Word_path & "\" & Replace(f.Name, ".pdf", ".doc"))
        wordDoc.Close False
        

Next f


End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hello there. Unfortunately, your code is not converting the pdf to a word document - what is happening is that you are telling word to open a file - it then does its best to understand what is in that file. You can't simply open a pdf in word and expect it tobe converted. You will need to open it as a pdf then try saving it as a word document. This solution from another site may help you: open a pdf with word vba in Excel
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top