Search

VBA to Read or Extract PDF Tables without Reader or Acrobat API - VBA PDF Automation-11

Subscribe Now!
New videos every Weekend!


Like what I do? Donate
Did I help you? Did one of my tutorials save you sometime? 
You can say thank you by buying me a cup of coffee, I go through a lot of it.
Help keep Greater Good resources free for everyone. Please donate today. 




This page is not monitored so for questions please comment on the youtube video page. For suggestions email vbaa2z.team@gmail.com

Download project or source code from below link(s)
Option Explicit
Const filename As String = "C:\Annual Report.pdf"
Sub readFromPDF()
'-----------------------------
'Thanks for downloading the code. Please visit our channel for a quick explainer on this code.
'Feel free to update the code as per your need and also share with your friends.
'Channel: Youtube.com/vbaa2z | Download free codes from http://vbaa2z.blogspot.com
'Author: L Pamai (vbaa2z.team@gmail.com)
'-----------------------------

Dim wApp As New Word.Application
Dim wDoc As Word.Document
Dim pg As Word.Paragraph
Dim wLine As String
Dim tbCount As Integer
Dim tbindx As Integer
Dim lr As Long
Dim tRow As Long, tCol As Long
wApp.Visible = True
Set wDoc = wApp.Documents.Open(filename, False)
For Each pg In wDoc.Paragraphs
   wLine = pg.Range.Text
   Debug.Print wLine
Next pg
tbCount = wDoc.Tables.Count
If wDoc.Tables.Count > 0 Then
For tbindx = 1 To tbCount
      With wDoc.Tables(tbindx)
         lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row + 2
         Cells(lr, 1).Value = "Table-" & tbindx
         For tRow = 1 To .Rows.Count
         lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
            For tCol = 1 To .Columns.Count
               On Error Resume Next
               'Debug.Print .Cell(tRow, tCol).Range.Text
               Cells(lr + 1, tCol).Value = WorksheetFunction.Trim(WorksheetFunction.Clean(.Cell(tRow, _
                  tCol).Range.Text))
               On Error GoTo 0
            Next tCol
         Next tRow
      End With
Next tbindx
End If
wDoc.Close False
Set wDoc = Nothing
wApp.Quit
Set wApp = Nothing
End Sub

No comments:

Post a Comment

Note: only a member of this blog may post a comment.