MakeFDF Error: 5 Invalid procedure call or argument VBAProject

underz

New Member
Joined
Jul 9, 2019
Messages
6
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:
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
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: MakeFDF Error: 5 Invalid procedure call or argument VBAProject
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: MakeFDF Error: 5 Invalid procedure call or argument VBAProject
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.

Sorry you are correct, I have asked another forum the same question... boss is breathin' down my neck lol
 
Upvote 0
Remove the On Error line then tell us which line of code causes the error.
 
Upvote 0
It is giving the same error when i remove the on error line, and when I click debug it goes to this line:
Shell "cmd /c " & """" & sFileName & """", vbHide
 
Upvote 0
So the macro itself works, when I comment that out and open the FDF manually, everything pulls. I think it's a company firewall or permission issue at this point.

Thanks for the help, I wouldn't have tried to debug this without your suggestion.

Cheers.
 
Upvote 0
Solution
When I try to execute your Shell command my antivirus (Malware Bytes) blocks it as an exploit. However, it is not a VBA error. So I am still stumped by what's causing your error.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top