Options

Running a Print Preview Excel Macro from Navision

mduckmduck Member Posts: 8
Has anyone created a print preview macro within Excel and called it from Navision?

When I called the macro, excel shows only the current sheet and the macro does not fire.
I first tried to call a chart print preview macro. Excel never came up and Navision locked up.

So I tried a simple print preview macro of just the data. As mentioned, only the current sheet is displayed.

Other defined macro called within Navision worked as defined except for the print preview.

Any help would be greatly appreciated.

Thanks,
Mike

See code below....

From Report OnPostDataItem()
TempExcelBuffer Record Excel Buffer
FullPath Text 200
Test2 name of the excel Macro

TempExcelBuffer.OpenBook2(FullPath);
TempExcelBuffer.RunMacro('test2');

Functions within Record Excel Buffer

Function OpenBook2
Passed Variable FileName Text 250

IF FileName = '' THEN
ERROR(Text001);
IF NOT EXISTS(FileName) THEN
ERROR(Text003,FileName);
IF NOT CREATE(XlApplication,TRUE) THEN
ERROR(Text000);
XlApplication.Workbooks.Open(FileName);
XlWorkBook := XlApplication.ActiveWorkbook;

Function RunMacro
XlApplication Automation 'Microsoft Excel 9.0 Object Library'.Application
Passed Variable MacroName Text 30

XlApplication.Run(MacroName);
YIELD;

Comments

  • Options
    jessewang98jessewang98 Member Posts: 1
    Hi mduck,
    I only see this topic from many websites, I know when you call a Macro from Excel file in Oracle, that is Objcet.invoke("file name",Run, Macro), and I read your code, that is Nivasion but not Axapta, do you know how to do it, call Macro from Excel file? any hit and piece code will be very helpfull for me

    Thanks
    Jesse
  • Options
    mduckmduck Member Posts: 8
    Hey Jesse,

    Not sure if you are using Navision but if you are,
    you can call a Macro from Navision by executing the the following code from any report or form.....
    ExcelBuffer.OpenBook2(FullPath);
    ExcelBuffer.RunMacro('test2');
    ExcelBuffer.GiveUserControl;
    

    FullPath is the Excel file (full path name) with the macro in the file called test2.

    Create new functions in table 370 Excel Buffer. See code below...

    Hope this helps....

    Mike

    Functions within Record Excel Buffer
    Function OpenBook2
    Passed Variable FileName Text 250
    
    IF FileName = '' THEN
    ERROR(Text001);
    IF NOT EXISTS(FileName) THEN
    ERROR(Text003,FileName);
    IF NOT CREATE(XlApplication,TRUE) THEN
    ERROR(Text000);
    XlApplication.Workbooks.Open(FileName);
    XlWorkBook := XlApplication.ActiveWorkbook;
    
    Function RunMacro
    XlApplication Automation 'Microsoft Excel 9.0 Object Library'.Application
    Passed Variable MacroName Text 30
    
    XlApplication.Run(MacroName);
    Yeild;
    
Sign In or Register to comment.