Created
April 23, 2014 16:43
-
-
Save darkoverlordofdata/11222959 to your computer and use it in GitHub Desktop.
Parse a PDF file in Excel VBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub PdfToText() | |
Dim answer | |
Dim source As String | |
Dim dest As String | |
Dim exe As String | |
Dim wsh As Object | |
Set wsh = VBA.CreateObject("WScript.Shell") | |
answer = Application.GetOpenFilename(Title:="Please choose a file to import", FileFilter:="PDF Files *.pdf (*.pdf),") | |
If answer = False Then | |
MsgBox "No file specified.", vbExclamation, "Warning" | |
Exit Sub | |
End If | |
source = answer | |
exe = "C:\Users\Bruce\Documents\pdftotext.exe" | |
dest = Replace(source, ".pdf", ".txt") | |
wsh.Run exe & " " & source & " -layout", vbHide, True | |
Workbooks.OpenText Filename:=dest, _ | |
StartRow:=1, _ | |
DataType:=xlFixedWidth, _ | |
TrailingMinusNumbers:=True | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment