Hi all,
searched the web quite a bit with no solution, unsure of how to solve this, and swore it work the other day... came into work and boom this error:
"MakeFDF Error: 5 Invalid procedure call or agument VBAProject"
Code:
searched the web quite a bit with no solution, unsure of how to solve this, and swore it work the other day... came into work and boom this error:
"MakeFDF Error: 5 Invalid procedure call or agument VBAProject"
Code:
VBA Code:
Option Explicit
#If VBA7 And Win64 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub Main()
Dim mainPDF As String
Select Case LCase(Worksheets("Statement").Range("Language").Value)
Case "english"
mainPDF = "english.pdf"
Case "French"
mainPDF = "french.pdf"
Case Else
mainPDF = "error.pdf"
End Select
If Len(Dir(ThisWorkbook.Path & "\" & mainPDF)) = 0 Then
MsgBox ThisWorkbook.Path & "\" & mainPDF, vbCritical, "Missing File - Macro Ending"
Exit Sub
End If
MakeFDF mainPDF
End Sub
Public Sub MakeFDF(Optional PDF_FILE As String = "error.pdf")
Dim sFileHeader As String
Dim sFileFooter As String
Dim sFileFields As String
Dim sFileName As String
Dim sTmp As String
Dim lngFileNum As Long
' Builds string for contents of FDF file and then writes file to workbook folder.
On Error GoTo ErrorHandler
sFileHeader = "%FDF-1.2" & vbCrLf & _
"%âãÏÓ" & vbCrLf & _
"1 0 obj<</FDF<</F(" & PDF_FILE & ")/Fields 2 0 R>>>>" & vbCrLf & _
"endobj" & vbCrLf & _
"2 0 obj[" & vbCrLf
sFileFooter = "]" & vbCrLf & _
"endobj" & vbCrLf & _
"trailer" & vbCrLf & _
"<</Root 1 0 R>>" & vbCrLf & _
"%%EO"
sFileFields = sFileFields & "<</T(TM)/V(" & Range("TM").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(Clinic)/V(" & Range("Clinic").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(ABP)/V(" & Range("ABP").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(Date)/V(" & Range("Date").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(TMPhoneNumber)/V(" & Range("TMPhoneNumber").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(Q1Check)/V(" & Range("Q1Check").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(Q2Check)/V(" & Range("Q2Check").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(Q3Check)/V(" & Range("Q3Check").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(Q4Check)/V(" & Range("Q4Check").Value & ")>>" & vbCrLf
sFileFields = sFileFields & "<</T(MTDPurchases)/V(" & Range("MTDPurchases").Value & ")>>" & vbCrLf
sTmp = sFileHeader & sFileFields & sFileFooter
' Write FDF file to disk
If Len(Range("TM").Value) Then
sFileName = Range("TM").Value
Else: sFileName = "FDF_DEMOTEST"
End If
sFileName = ActiveWorkbook.Path & "\" & sFileName & ".fdf"
lngFileNum = FreeFile
Open sFileName For Output As lngFileNum
Print #lngFileNum, sTmp
Close #lngFileNum
DoEvents
' Open FDF file as PDF
Shell "cmd /c " & """" & sFileName & """", vbHide
Exit Sub
ErrorHandler:
MsgBox "MakeFDF Error: " + Str(Err.Number) + " " + Err.Description + " " + Err.Source
End Sub