[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

macro not running for Excel in SAP

Asked by jan1977 in SAP ERP, Microsoft Excel Spreadsheet Software, Visual Basic Programming

Tags: Excel, SAP, Macro, activeprinter

Hello,
I have a problem running a particular macro from an Excel form that is displayed in SAP.

Context:
In my company we use an form build in MS Excel. Some of the worksheets in de Excel were filled with data that were extracted from SAP. Several transaction where needed to get all the data. In the light of a process optimization a custom build workflow-like application has been build in ABAP.
The application fills the SAP-data into the Excel form. To do this the user hits the button, SAP gets the template of the form and the SAP data are filled. The Excel form is shown 'in place' within the SAP user interface. The Excel toolbar showed below the SAP Toolbar.
The Excel form contains multiple macro's and one of them is used to create a pdf-file from the active worksheet, using the "Win2PDF" printer.

Problem:
The macro for creating the pdf-file does not run when the form is displayed in SAP. It throws an error 1004 "method ActivePrinter of object_Application failed". The error is thrown at the first line of the following code (Ne00 is an example):
Application.ActivePrinter = "Win2PDF op Ne00:"
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
        "Win2PDF op Ne00:", Collate:=True

Analysis thus far:
* All other macro's work fine (showing/ hiding worksheets, copying cells between worksheets, changing cell protection, protecting/ unprotecting worksheets)
* When the form is filled within SAP and saved locally, the macro to print the pdf works fine.
* Code has been provided to check on the port of the printer (NE00 in the above example). This code has been tested and worked fine.
* If the form is displayed within SAP, it is possible to select the Win2PDF printer through the MS Excel toolbar. After selecting it, the pdf is printed.
* A macro was recorded when the form was shown in SAP,  while the print command was given through the MS Excel toolbar. This macro showed the code posted under "Problem" above. When the recorded macro was run, the error also occurs.

The ABAP programmers resonsible for the realization of the application did not know how the macro could be fixed to run within SAP. I'm not a SAP expert, so unfortunately I can not tell in detail how Excel is called from within SAP.

Additional information:
* The version of Excel currently used here is 2003.
* The form is shown in SAP ECC 6.0
* A screenshot attached to this message shows how the SAP screen looks when the Excel form is opened (I'm not sure if I may 'publish' the exact form. I therefore made a screenshot with a blank worksheet).
 
I hope someone knows how to fix this problem, as it would make many people happy. I did a lot of searching on the internet, but it did not provide me with a solution.

Kind regards,
Jan.
Attachments:
 
screen shot of the MS Excel form shown in SAP
screen shot of the MS Excel form shown in SAP
 
[+][-]10/16/09 09:37 AM, ID: 25591043Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625