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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Closing Excel Sheet

(0) ShareShare
ReportReport
Posted on by

Hi All,

After Read from Excel i use this Code but after run Menu Item I give me an warning that This Excel is Modified by 'User' i Closed All Excel then run the meniitem again but the same warning 

            application.displayAlerts(false);
            workbooks.close();
            application.quit();
            application.finalize();

Can any one Help Me in this Error??

Regards.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Andrew Xu Profile Picture
    3,877 on at

    you should only need,

    application.displayAlerts(false);

    application.quit();

  • Walid Gamal Profile Picture
    on at

    Hi Andrew

    I tried It but the Same Warning

    Is there any other Idea?

  • Andrew Xu Profile Picture
    3,877 on at

    That worked for me. Could you paste your code completely?

  • Walid Gamal Profile Picture
    on at

    Hi Andrew

    My Code is For Closing Last Discount Journal

    static void UpdateSalesDiscountCrossCompany(Args _args)
    {
        SysExcelApplication                           application;
        SysExcelWorkbooks                           Workbooks;
        SysExcelWorkbook                            Workbook;
        SysExcelWorksheets                          worksheets;
        SysExcelWorksheet                           worksheet;
        SysExcelCells                               cells;
        COMVariantType                              type;
        InventTable                                 inventTable;
        PriceDiscAdmTrans                           priceDiscAdmTrans,priceDiscAdmTransobj;
        PriceDiscAdmTrans                           priceDiscJourAdmTra;
        AxdDocumentParameters                       axdDocumentParameters;
        PricePriceDiscJournalService                PriceDiscSvc;
        PricePriceDiscJournal                       PriceDiscJour;
        PricePriceDiscJournal_PriceDiscAdmTrans     PriceDiscJourAdmTrans;
        PricePriceDiscJournal_InventDim             PriceDiscJourDim;
        CompanyInfo                                 company;
        container                                   containerofall,mycontainer2,mycontainer3;
    
        // keys return from create process
        AifEntityKeyList                            keys;
        PriceDiscAdmTable                           PriceDiscAdmTable;
    
        ItemRelation                                itemRelation;
        ItemRelation                                itemRelation2;
        PriceDiscItemCode                           ItemCode;
        AmountCur                                   amount;
        FileName                                    filename;
        FromDate                                    fromdate;
        ToDate                                      todate;
        int                                         row ,i,n,j,l;
        CompanyId                                   currentCompany;
        ItemId                                      itemnumber;
        List                                        mylist;
    
        PriceDiscTable                              pricedisc;
        DialogButton                                diagBut;
        str                                         strMessage;
        str                                         strTitle    ;
        MenuFunction updateDiscount;
    
        strTitle = "Confirmation";
        strMessage="Are you sure you want to Post new Sales Discount Journal?";
        diagBut = Box::yesNo(
        strMessage,
        DialogButton::No, // Initial focus is on the No button.
        strTitle);
        if (diagBut == DialogButton::Yes)
        {
            application = SysExcelApplication::construct();
            Workbooks = application.Workbooks();
            //specify the file path that you want to read
            filename = @"C\Distributor Sales Discount.xlsx";
            try
            {
                Workbooks.open(filename);
            }
            catch (Exception::Error)
            {
                throw error("File cannot be opened.");
            }
            Workbook = Workbooks.item(1);
            worksheets = Workbook.worksheets();
            worksheet = worksheets.itemFromNum(1);
            cells = worksheet.cells();
            row=1;
    
            do{
    
            row++;
    
            ItemCode        = cells.item(row, 2).value().int();
            itemRelation    = cells.item(row, 3).value().bStr();
            fromdate        = cells.item(row, 6).value().date();
            if(ItemCode ==   0)
                {
                while select forupdate crossCompany pricedisc where pricedisc.relation==PriceType::LineDiscSales && pricedisc.ItemRelation==itemRelation && pricedisc.ToDate>=fromdate
                {
                    changeCompany(pricedisc.dataAreaId)
                    {
                        ttsBegin;
                        pricedisc.ToDate=fromdate-1;
                        pricedisc.update();
                        ttsCommit;
                    }
                }
            }
            else if(ItemCode    ==   2)
            {
                while select forupdate crossCompany pricedisc where pricedisc.relation==PriceType::LineDiscSales && pricedisc.ItemCode==ItemCode && pricedisc.ToDate>=fromdate
                {
                    changeCompany(pricedisc.dataAreaId)
                    {
                        ttsBegin;
                        pricedisc.ToDate=fromdate-1;
                        pricedisc.update();
                        ttsCommit;
                    }
                }
            }
            type = cells.item(row+1, 1).value().variantType();
        }
    
        while (type != COMVariantType::VT_EMPTY);
        application.displayAlerts(false);
        application.quit();
    
        info("Old Sales Discount has been Closed");
        updateDiscount  = new MenuFunction(menuItemActionStr(CreateSalesDiscountFinal), MenuItemType::Action);
        updateDiscount.run();
        }
    }


  • Andrew Xu Profile Picture
    3,877 on at

    You code should work just fine. Could you open your excel file to see if it says it's being modified by other users to see if you indeedly have that excel process killed? Then run your code again.

  • Walid Gamal Profile Picture
    on at

    I do That and retry again

    it say that file is being modified by my user

    I think this mean that closing is not Working.

  • Andrew Xu Profile Picture
    3,877 on at

    when manually open your excel file, do you see that warning?

  • Walid Gamal Profile Picture
    on at

    Hi Andrew

    No It not Appear

  • Andrew Xu Profile Picture
    3,877 on at

    remove

       updateDiscount  = new MenuFunction(menuItemActionStr(CreateSalesDiscountFinal), MenuItemType::Action);

       updateDiscount.run();

    in your code, and try again.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 26

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans