Link to home
Start Free TrialLog in
Avatar of Fritz Paul
Fritz PaulFlag for South Africa

asked on

Help with printing specified sheets to PDF with VBA using ExportAsFixedFormat

I am using Excel 2010.

The following code works for me to print all sheets after the second sheet.

       ActiveWorkbook.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=sPDFPath & sPDFName, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True, _
        From: = 3

Open in new window


However I want to specify a specific list of sheets to print like

   
 ThisWorkbook.Sheets(Array("Cover Page", "Net Position")).Select

Open in new window

and then somehow print the selection. One thing that I tried was

    ThisWorkbook.Sheets(Array("Cover Page", "Net Position")).Select
    
   
    Selection.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=sPDFPath & sPDFName, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True, _
        From:=3

Open in new window


This gives me a blank pdf file

Can you help please
Avatar of Rgonzo1971
Rgonzo1971

Hi,

Pls try

ThisWorkbook.Sheets(Array("Cover Page", "Net Position")).Select
   
   
    Selection.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=sPDFPath & sPDFName, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True, _
        From:=1

Regards
Avatar of Fritz Paul

ASKER

Thanks,
I tried that now and also without the "From:=1. In both cases the selection takes place, but the resulting pdf is only two blank pages.
What does work is to hide the sheets which I don't want to print and then do the "ActiveWorkbook.ExportAsFixedFormat .....",
ASKER CERTIFIED SOLUTION
Avatar of Fritz Paul
Fritz Paul
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have now tried so many ways and there seem to be no solution except for the negative approach, specifying what not to print. I am now content with that and don't want more of your excellent brains to be spent on this problem.
Thanks to Rgonzo1971 for his help.