web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to quit a excel session correctly

(0) ShareShare
ReportReport
Posted on by 140

Hi,

I'm using AX 4.0 SP2 Build 4.0.2501.116 and I'm having a problem closing a excel session. After starting a excel session with the SysExcelApplication object and passing data to the excel sheet, I'm trying to quit this session using the SysExcelApplication.quit() and SysExcelApplication.finalize() method, but the excel.exe ist still remains in the task manager, does anyone know how to deal with this problem?

Greetings

Ralph

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Try calling SysExcelApplication.displayAlerts(false) before you call quit().  What likely is happening is that it's waiting for an interaction with the user to save the sheet before it closes.  If you tell it to not prompt, that might do it for you.

  • Ralph Eichenauer Profile Picture
    140 on at

    sorry I didn't mention that, but after initializing the SysExcelApplication I called SysExcelApplication .displayAlerts(false) and the SysExcelApplication .visible(true), so I can see what's going on.

    So this should not be the problem.

  • Qiang Ying Profile Picture
    55 on at

    Colleague of mine had that problem recently. I agree with Justin about that the application seems to be waiting for somthing. We got the problem solved by calling save before calling quit. Strange result: save throws an error (specifically that the call failed) but then the application closes, not to be found in the task list anymore. My colleague built a silent swallow try/catch around the call to save.

  • Community Member Profile Picture
    on at

    Hmm.  How about setting your variable to null after you've finished with it?  My use of Excel from Dynamics is rather simple, just getting the value from a built-in function that doesn't have a good mathematical representation, and then quitting.  So it doesn't stay open for longer than the method is in scope.  Your situation might be different than mine, but here's what I'm doing that closes excel immediately after the quit() call.

    void calcNormSInvValue()
    {
        SysExcelApplication     application;
        SysExcelWorkBooks       workbooks;
        SysExcelWorkBook        workbook;
        SysExcelWorksheets      worksheets;
        sysExcelWorksheet       worksheet;
        SysExcelCells           cells;
        SysExcelCell            cell;
        COMVariant              value;
        ;

        application = SysExcelApplication::construct();
        workbooks = application.workbooks(); //gets the workbook object
        workbook = workbooks.add();  // creates a new workbook
        worksheets = workbook.worksheets(); //gets the worksheets object

        worksheet = worksheets.itemFromNum(1);//Selects the first worksheet in the workbook to insert data
        cells = worksheet.cells();
        cell = cells.item(1, 1);
        cell.value(strfmt("=NORMSINV(%1%)",safetyStockPercent));
        value = cell.value();
        normSInvValue = value.double();
        application.displayAlerts(false);
        application.quit();
    }

    Only thing to note is that this is using AX 2009 SP1, so that might have a difference.

  • Ralph Eichenauer Profile Picture
    140 on at

    Thanks for your suggestions, I tried both calling the save before quit and the displayAlerts(false) method before quit. But still the same behaviour, I made the application visible, to see if there are any messages or warnings, with no result. Is there a possibility in AX to catch the proccess and kill it maybe by using the WinApi class?

  • Qiang Ying Profile Picture
    55 on at

    My first thoughts: Should be possible, if not through WinApi then through the use of .NET in AX. I would assume that this is even more difficult, since AX is pretty weird when it comes to all that permission stuff, probably even more so when trying to kill other processes. On the other hand, the process was spawned by the AOS user in the first place.

    So I would be glad to hear the results of that attempt.

  • Luegisdorf Profile Picture
    1,930 on at

    You can try to close the excel with workbook.close()

    But since this method is not direct supported by SysExcelWorkbook you need to do it so:

    COM x;

    x = workbook.comObject;

    x.close();

    Another step to check:

    - Sure, it's your excel application which is still running?

    - Set pointer to SysExcelApplication object to null (application = null);

  • Ralph Eichenauer Profile Picture
    140 on at

    As none of the tips worked out for me I installed a demo machine running XP installed the AX client an MS Office 2003 SP1 and it works perfectly excel is shut down correctly. So I inspected the office Version installed on the test server which run Windows Server 2003, there th office is version 2003 also, but with SP3 installed, so this might be the problem.

    So I guess this is a problem of MS Office.

    So thanks for all your help.

    Greetings

    Ralph

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans