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 NAV (Archived)

Exporting to a new document

(0) ShareShare
ReportReport
Posted on by

Hi, I Have this code which is used when exporting to excel from Navision. This code is currently is looking for an existing document to update, how can I change this for creating a fresh new document. 

recCPSetup.FINDFIRST;

strFilepath:='U:\CustomerParts.xlsx'; //Specify the location where the excel file is stored locally

IF ISCLEAR(xlApp) THEN
CREATE(xlApp, FALSE, TRUE);

xlApp.Visible(TRUE);

//1. Opening the excel file
xlBook:=xlApp.Workbooks.Open(strFilepath);//specify your file path with the filename.xls(x)

xlBook:=xlApp.ActiveWorkbook;

//2. Specify the excel sheet name
xlSheet := xlBook.Worksheets.Item('Sheet1');

Name DataType Subtype Length
xlApp / Automation /  'Microsoft Excel 16.0 Object Library'.Application
xlBook /  Automation / 'Microsoft Excel 16.0 Object Library'.Workbook
xlSheet / Automation / 'Microsoft Excel 16.0 Object Library'.Worksheet

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Amol Salvi Profile Picture
    18,698 on at

    xlBook:=xlApp.Workbooks.Open(strFilepath);//specify your file path with the filename.xls(x)

    Remove this line and check

  • Community Member Profile Picture
    on at

    Thanks however It Errors on this Line 

    xlSheet := xlBook.Worksheets.Item('Sheet1');

    8171.128.PNG

  • Suggested answer
    Yogesh Kulkarni_ Profile Picture
    1,762 on at

    Try using Create Function and pass automation variable of type Application.

    Please refer:

    https://msdn.microsoft.com/en-us/library/dd355255(v=nav.90).aspx

    http://forum.mibuso.com/discussion/927/tips-tricks-excel-automation

    -Yogesh Kulkarni
    Please verify, if you find answer helpful.

     

  • Suggested answer
    Mohana Yadav Profile Picture
    60,993 Super User 2025 Season 2 on at

    please check excel buffer table.

    functions in this table will give you idea.

  • Suggested answer
    Amol Salvi Profile Picture
    18,698 on at

    You need to rewrite it either using excel buffer or excal automation

  • Community Member Profile Picture
    on at

    I'm trying to avoid using Excel Buffer as I want to set the width of columns, and as far as I'm aware it can't be done with Excel Buffer.

  • Verified answer
    Community Member Profile Picture
    on at

    Final working solution:

    IF ISCLEAR(xlApp) THEN

     CREATE(xlApp, FALSE, TRUE);

    xlBook:=xlApp.Workbooks.Add;

    xlSheet := xlBook.Worksheets.Item('Sheet1');

    Code...

    xlSheet.Activate();

    xlApp.Visible(TRUE);

  • Community Member Profile Picture
    on at

    Good afternoon, how could I create several graphics on an excel sheet with navision automation?

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 NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans