Frage

I am using the ExportAsFixedFormat method of EXCEL, in order to export a workbook in PDF through ABAP.

Desired outcome: I want to save the entire workbook, instead of saving only the active sheet.

Issue: My problem is that I cannot use the range parameter as it seems that it has no effect in EXCEL.

I tried recording a macro in EXCEL using the Save As Type: PDF, and selecting the Entire Workbook in the Publish What section of the Options.

Unfortunately, whether you only set in the Options the Active Sheet(s), or the Entire Workbook, the macro that is recorded is exactly the same (shown bellow), since I guess the options are included in the IncludeDocProperties, which I cannot pass through my current method.

Macro:

ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\foo.pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    False

Taking into consideration the code bellow, which I am currently using in my class method. I am looking for a way to alter my selection of the Active Sheet(s) or finding a way to pass the desired option of publishing the Entire Workbook.

Please note that I want to find a solution through ABAP coding and not through VBA, since my options are limited. Also the amount of sheets that are included in the Workbook is unknown, as they are populated dynamically. Using the select option would not be in favor of the application.

ABAP Method:

call method of worksheet 'ExportAsFixedFormat'
  exporting
  #1 = '0'
  #2 = fullpath.

Thanks in advance for any comments.

War es hilfreich?

Lösung

Your ABAP code actually shows the problem.

You are calling the method on the worksheet, and that will only export that worksheet.

What you need to do is call the method on the corresponding workbook to export all the sheets.

Here is some sample ABAP code that will create a workbook, populate two sheets and do the export. The result PDF has a page per sheet:

data: excel type obj_record.
data: workbooks type obj_record.
data: workbook type obj_record.
data: sheet type obj_record.
data: range type obj_record.

* Start Excel and create a new workbook
create object excel 'Excel.Application'.
get property of excel 'Workbooks' = workbooks.
call method of workbooks 'Add'.

* Set first cell in first sheet to a value
call method of excel 'Sheets' = sheet exporting #1 = 1.
call method of sheet 'Cells' = range EXPORTING #1 = 1 #2 = 1.
set property of range 'Value' = 'Page 1'.

* Set first cell in first sheet to a value
call method of excel 'Sheets' = sheet exporting #1 = 2.
call method of sheet 'Cells' = range EXPORTING #1 = 1 #2 = 1.
set property of range 'Value' = 'Page 2'.

* Get handle on the (first) workbook
get property of excel 'Workbooks' = workbook exporting #1 = 1.

* Export the entire workbook as PDF
call method of workbook 'ExportAsFixedFormat'
  exporting
  #1 = '0'
  #2 = 'C:\temp\excelpdfexport'.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top