• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1193
  • Last Modified:

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
0
Fritz Paul
Asked:
Fritz Paul
  • 3
1 Solution
 
Rgonzo1971Commented:
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
0
 
Fritz PaulAuthor Commented:
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 .....",
0
 
Fritz PaulAuthor Commented:
I still get blank pages.

Thanks a lot for your help, but I think I will just work with hiding those pages that I don't want to print.
0
 
Fritz PaulAuthor Commented:
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now