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)

Opening excel from X++ , Does not open as active window

(0) ShareShare
ReportReport
Posted on by 690

Hi all,

I am trying to open an excel application/workbook from X++, But the problem is that the excel does not open as the active/front window. Instead it remain on the background and just blinks on the task bar.

 

Below is the code I am using. I have removed all the cell writing code to just make it simpler. I do a lot of cell writing and then I open the excel.

I want the excel when opening to open as the front/active window and be the first visible window above Dynamics AX window.

 

IF you look at "Export to excel" feature in Dynamics AX forms (available on every form) then it opens as the active window and on opening remains on top of the Dynamics AX window. That is exactly what I want my users to have experience of.

 

My code :

static void Job3(Args _args)
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    ;

    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    workbook = workbooks.add();
    application.visible(true);
}


- Girija

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    //Here are the accurate results with 1 minute of effort

    static void ExcelFileOpenCustom(Args _args)
    {
        
        #Excel
    
        HWND    hwnd;
        
        SysExcelApplication application;
        SysExcelWorkbooks workbooks;
        SysExcelWorkbook workbook;
        ;
     
        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
        workbook = workbooks.add();
        application.visible(true);
        
        
        
    
        hwnd = WinAPI::findWindow(#XLMAIN,'');
        WinAPI::bringWindowToTop(hwnd);
        WinAPI::setForegroundWindow(hwnd);
    }
    


    //cheers!

  • Girija Shankar Beuria Profile Picture
    690 on at

    You one minute of effort did help.

    Thanks !!!!

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