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)

Running an excel macro from NAV 2013

(0) ShareShare
ReportReport
Posted on by 652
Hi,

I am not so experienced in .net yet. So my excuses if I ask stupid things.

I want to execute an excel macro out of NAV 2013 R2 and I use 2 variables for this:

Name DataType Subtype Length
XlApp DotNet Microsoft.Office.Interop.Excel.ApplicationClass.'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
NullGbl DotNet System.Object.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

I cannot compile my NAV object if I do not add 30 parameters to the "run" function so I use the "NullGbl" variable for this:

  XlApp.Run('CreateSubtotals',NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,
   NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl,NullGbl);


"CreateSubtotals" is the name of the macro. When executing the code, I get an error from excel that it does not expect so many parameters:

Attachment:
File comment: The error I get from excel
Error.png
Error.png [ 11.99 KiB | Viewed 117 times ]


And indeed, the macro has no parameters, but NAV does not compile if I don't add them :( .

Any ideas?

Thanks,
Steven

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    keoma Profile Picture
    32,729 on at

    hi,

    better check table ExcelBuffer. there you have functions like OpenBook and CloseBook using assembly Microsoft.Dynamics.NAV.Integration.Office (variable xlHelper). For running excel macros better develope your own assembly.

  • stevdeb Profile Picture
    652 on at

    Hi Jonathan,

    Thanks for your answer. I did investigate the excelbuffer functions, but none of them can run a macro.  I expected it to be possible to run the macro directly with DotNet. But I think we will end up writing an own assembly, as you suggest.

    Thanks,

    Regards

  • keoma Profile Picture
    32,729 on at

    i made a little research about that issue. problem is the "Missing" enum value. it seems that it's not accepted in c/al. as result you get that kind of error (parameter mismatch, ...). then i developed an assembly prototype. with that it worked fine.

    if you need help for developing that kind of assembly, you can contact me 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

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