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

Problems with AX 2009 and Office Word Interop

(0) ShareShare
ReportReport
Posted on by 1,719

Hi all,

I am having trouble with the Office Word API trying to create a Word documment throw the Interop libraries.

I have the following cod in AX:

 

    Microsoft.Office.Interop.Word.ApplicationClass  word;
    Microsoft.Office.Interop.Word.Documents         docs;
    Microsoft.Office.Interop.Word.DocumentClass     doc;
    int i;
    ;

    new InteropPermission(InteropKind::ClrInterop);

    word = new Microsoft.Office.Interop.Word.ApplicationClass();
    doc  = new Microsoft.Office.Interop.Word.DocumentClass();

    docs = word.get_Documents();
    doc  = docs.Add();

    CodeAccessPermission::revertAssert();

 

It seems OK but the AX compiler throws an error in the line marked in red, saying that the Add function doesn't exists in the Documents Class. It obviously exists, the editor helps with the parameters etc, and the method is docummented:

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.documents.add.aspx

but the compiler still doesn't allow to use it ...

Any help will be appreciated,

thanks!

 

j.a.estevan
http://www.jaestevan.com

 

*This post is locked for comments

I have the same question (0)
  • Luegisdorf Profile Picture
    1,930 on at

    I don't know the reason of the compiler reaction, but you can try use reflection until you've found the true reason:

    Sytem.Type docsType;

    ...

    ...

    docsType = doc.GetType();

    docsType.InvokeMember("Add", ....);

    I know it's ugly, but may be you can use it as temporary workaround. I've often used it to avoid wrong compiler messages ...

    Regards

  • Tobias Brüggendick Profile Picture
    31 on at

    @jaestevan:

    Hi Jaestevan,

    did you find a solution for the problem?

    Best Regards,

    Tobias

  • Suggested answer
    Denis Patrakov Profile Picture
    on at

    Although all the parameters in the method definition are marked as optional the X++ compiler doesn't "understand" that so in X++ you're required to pass all the "missing" parameters (where "missing" is a special parameter value for omitted parameters like in VB.NET)

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

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans