Tuesday, July 7, 2020

Convert word document to pdf using VBA

Option Explicit

Sub vba_word_to_pdf()
Dim output_file As String
output_file = ActivePresentation.Path & "\" & Left(ActivePresentation.Name, Len(ActivePresentation.Name) - 5) & ".pdf"

'MsgBox ("hello")
ActivePresentation.ExportAsFixedFormat output_file, ppFixedFormatTypePDF, ppFixedFormatIntentPrint

End Sub

Convert all slides in a powerpoint presentation to a pdf using VBA

Option Explicit

Sub vba_powerpoint_to_pdf()
Dim output_file As String
output_file = ActivePresentation.Path & "\" & Left(ActivePresentation.Name, Len(ActivePresentation.Name) - 5) & ".pdf"

'MsgBox ("hello")
ActivePresentation.ExportAsFixedFormat output_file, ppFixedFormatTypePDF, ppFixedFormatIntentPrint

End Sub

Monday, July 6, 2020

Read Pdf without Acrobat

Enable Microsoft Scripting Runtime reference

Option Explicit

Const form_filename As String = "C:\Users\allso\Desktop\New Customer Registration Form.pdf"

Sub read_pdf_form_vals()

Dim fso As New FileSystemObject
Dim tStream As TextStream
Dim vLine As String, vKey As String, fieldlist() As Variant, arrIndx As Integer
Dim i As Integer


vKey = ") Tj"


Set tStream = fso.OpenTextFile(form_filename, ForReading, False)
Do While Not tStream.AtEndOfStream
vLine = tStream.ReadLine
If InStr(vLine, vKey) > 0 Then
vLine = Replace(Right(vLine, Len(vLine) - 1), vKey, "", 1)
ReDim Preserve fieldlist(0 To arrIndx)
fieldlist(arrIndx) = vLine

Debug.Print vLine

arrIndx = arrIndx + 1

End If

'Debug.Print vLine
Loop
For i = UBound(fieldlist) To LBound(fieldlist) Step -1
Debug.Print fieldlist(i)
Next i

Set tStream = Nothing
Set fso = Nothing


End Sub