Skip to content

Instantly share code, notes, and snippets.

@darkoverlordofdata
Created April 23, 2014 16:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darkoverlordofdata/11222959 to your computer and use it in GitHub Desktop.
Save darkoverlordofdata/11222959 to your computer and use it in GitHub Desktop.
Parse a PDF file in Excel VBA
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