Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Running an excel macro from NAV 2013

Posted on by 650
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

  • keoma Profile Picture
    keoma 32,675 on at
    RE: Running an excel macro from NAV 2013

    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.

  • stevdeb Profile Picture
    stevdeb 650 on at
    RE: Running an excel macro from NAV 2013

    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

  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: Running an excel macro from NAV 2013

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans