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

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

How to Saveas() Excel file without asking Do you want to Replace Existing File Message.

(0) ShareShare
ReportReport
Posted on by 245

Hello Experts,

How can we do Saveas() a Excel file Directly without displaying confirmation message (by Writing Code-unit).

Thank you.

I have the same question (0)
  • AlexDen Profile Picture
    90 on at
    RE: How to Saveas() Excel file without asking Do you want to Replace Existing File Message.

    Hello,

    Try to use Save() instead of SaveAs().

    Or set DisplayAlerts to False before saving the file:

    ExcelApplicationClass.DisplayAlerts := FALSE;
    ExcelWorkbook.SaveAs();
    ExcelApplicationClass.DisplayAlerts := TRUE;
  • Manikanta_501 Profile Picture
    245 on at
    RE: How to Saveas() Excel file without asking Do you want to Replace Existing File Message.

    As you said , I modified code as like below(added code for Deleting existing file from local system).

    Capture_5F00_3.PNG

    But while running this code I am getting error , below.

    Capture_5F00_4.PNG

  • Suggested answer
    RockwithNav Profile Picture
    7,980 Super User 2025 Season 2 on at
    RE: How to Saveas() Excel file without asking Do you want to Replace Existing File Message.

    Ideally this Message will only come when you already have a file at that location with the same name so technically this is a correct message, if want to get rid of this message then you need to first check if that file already exist there and if yes then you need to move or delete that file.

  • Manikanta_501 Profile Picture
    245 on at
    RE: How to Saveas() Excel file without asking Do you want to Replace Existing File Message.

    Thanks for Your Replay,

    Actually I am Unprotecting the Excel file & Saving that file in same path. The code is like below.

    156.PNG

  • Suggested answer
    I Gusti Made Ari Profile Picture
    3,594 on at
    RE: How to Saveas() Excel file without asking Do you want to Replace Existing File Message.

    Use Outstream , sample code : 

    File.CREATE('C:\YourExcelFile.xls');

    File.CREATEOUTSTREAM(Outstr);

    YourRec.SETFRANGE("FIeld 1",Filter1);

    IF YourRef.FINDFIRST THEN BEGIN

        RecordRef.SETTABLE(YourRec);

        REPORT.SAVEAS(REPORT::"Your Report Name",'',REPORTFORMAT::Excel,OutStr,RecordRef)

    END;

    https://docs.microsoft.com/en-us/dynamics-nav/createoutstream-function--file-

    FIle.CLOSE

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,689 Super User 2025 Season 2

#2
Sumit Singh Profile Picture

Sumit Singh 2,631

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,212

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans