PDF File to Excel by using VBA coding

Farooqui Noor

New Member
Joined
Dec 31, 2019
Messages
27
Office Version
  1. 2019
Platform
  1. Windows
Is it possible to convert PDF File to Excel by using VBA coding. kindly provide the coding

can anyone improve following coding

VBA Code:
Option Explicit

Sub PDF_To_Excel()

Dim setting_sh As Worksheet
Set setting_sh = ThisWorkbook.Sheets("Setting")

Dim pdf_path As String
Dim excel_path As String

pdf_path = setting_sh.Range("E11").Value
excel_path = setting_sh.Range("E12").Value

Dim fso As New FileSystemObject
Dim fo As Folder
Dim f As File

Set fo = fso.GetFolder(pdf_path)

Dim wa As Object
Dim doc As Object
Dim wr As Object

Set wa = CreateObject("word.application")

'Dim wa As New Word.Application
wa.Visible = True
'Dim doc As Word.Document

Dim nwb As Workbook
Dim nsh As Worksheet
'Dim wr As Word.Range

For Each f In fo.Files
Set doc = wa.documents.Open(f.Path, False, Format:="PDF Files")
Set wr = doc.Paragraphs(1).Range
wr.WholeStory


Set nwb = Workbooks.Add
Set nsh = nwb.Sheets(1)
wr.Copy

nsh.Paste
nwb.SaveAs (excel_path & "\" & Replace(f.Name, ".pdf", ".xlsx"))

doc.Close False
nwb.Close False
Next

wa.Quit

MsgBox "Done"

End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Farooqui Noor

New Member
Joined
Dec 31, 2019
Messages
27
Office Version
  1. 2019
Platform
  1. Windows
I Have marks of students in PDF file in a tabular form. I want to extract the same data from PDF to excel in each column and in each row
 

Watch MrExcel Video

Forum statistics

Threads
1,119,183
Messages
5,576,574
Members
412,734
Latest member
rubinrods
Top