Save Entire Workbook as PDF Excel 2010 (C#)

后端 未结 1 952
执念已碎
执念已碎 2021-01-14 00:30

Is there anyway to save you entire workbook as a pdf in excel. I found this, http://msdn.microsoft.com/en-us/library/bb407651(v=office.12).aspx, but it does not exactly tell

相关标签:
1条回答
  • 2021-01-14 00:37

    In 2010 you can save the entire workbook in PDF by making each sheet an "Active" sheet. Sounds strange but if you notice the print options when you do a pdf there is no option for workbook. To get around this open an excel file and fill in some data in 2-3 work sheets. Now hold your ctrl key and click on each other workbook, it will then become a "Group".

    You will notice the [GROUP] name appear at the top of the excel file and now when you print the excel file it will print the entire workbook.

    Try this out for yourself. In code, you just need to make each work sheet an active worksheet. I don't work much with the excel object model but it might be worth doing a macro for this and looking at the code.

    I recorded a macro and here is the VBA:

    Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

    Looks as though you just need to store each sheet in an array and then simply

    Sheets(MyArray).Select

    This will then make all sheets active and [grouped] and then you can run a print out to pdf. By recording the macro it also presented the options to print to pdf:

    `ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\MyAccount\Desktop\test.pdf", Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
        True`
    

    In this case active sheet is your group of sheets that you have stored in an array.

    0 讨论(0)
提交回复
热议问题