Question : Variable not defined error using VBA ExportAsFixedFormat Type:=xlTypePDF in excel 2003

I'm using ExportAsFixedFormat to print worksheet as a pdf

My issue is the code below will not compile in the earlier versions of excel due to xlTypePDF being an undefined variable in those earlier versions.

Some users of the program will have versions of XL pre version 12 which do not support ExportAsFixedFormat Type:=xlTypePDF, I'm intending to use ExportAsFixedFormat  for versions higher than 12 and print PDFCreator (or somethingsimilar)  if the excel version is less than 12.

I could just turn off option explicit but I'm sure there's a much more eloquent solution.

Can someone please tell me how to get around this error?

(Or even better help me to make ExportAsFixedFormat work to print to pdf for earlier versions of Excel (make my own version to work for all versions of XL so I dont have to use a 3rd party utility to create the pdf)?)
1:
2:
3:
4:
5:
6:
7:
8:
sub  MakePDF()
If Application.Version > 11 Then
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
        "C:\\Book1.pdf", Quality:=xlQualityStandard, IncludeDocProperties _
        :=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Else
    MakePDF_UsePDFCreator
End If

Answer : Variable not defined error using VBA ExportAsFixedFormat Type:=xlTypePDF in excel 2003

I have used the numerical equivalent

If lExcelVersion > 11 Then
    ActiveSheet.ExportAsFixedFormat Type:=0, Filename:= _
        "C:\Book1.pdf", Quality:=0, IncludeDocProperties _
        :=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
Random Solutions  
 
programming4us programming4us