NAV 2013/Word Interop - "Item is not a property" error
tomddlc
Member Posts: 8
Hi all,
I'm hoping there is a .Net Interop expert in here, who can help me :-)
I have a problem using .Net Interop in NAV 2013. I'm trying to loop through all members of MailMergeField in a MailMergeFields collection.
My code looks like this:
WordDocument := WordHelper.CallOpen(WordApplication,TemplateFile,FALSE,FALSE);
WordDocument.Fields.Update;
WordMailMerge:=WordDocument.MailMerge;
WordMailMergeFields := WordMailMerge.Fields;
NoOfFields := WordMailMergeFields.Count;
FOR I := 1 TO NoOfFields DO BEGIN
WordMailMergeField := WordMailMergeFields.Item(I);
"Do something"
END;
I use the WordHelper class to open the document, and native Word.Interop for the rest. The code compiles nicely, but when I run it, I get an error saying that "Item is not a property" - when I try to call WordMailMergeFields.Item(I).
The variable "NoOfFields" is being set, so I my WordMailMergeFields is initialized correctly.
I would love to hear any suggestions.
I'm hoping there is a .Net Interop expert in here, who can help me :-)
I have a problem using .Net Interop in NAV 2013. I'm trying to loop through all members of MailMergeField in a MailMergeFields collection.
My code looks like this:
WordDocument := WordHelper.CallOpen(WordApplication,TemplateFile,FALSE,FALSE);
WordDocument.Fields.Update;
WordMailMerge:=WordDocument.MailMerge;
WordMailMergeFields := WordMailMerge.Fields;
NoOfFields := WordMailMergeFields.Count;
FOR I := 1 TO NoOfFields DO BEGIN
WordMailMergeField := WordMailMergeFields.Item(I);
"Do something"
END;
I use the WordHelper class to open the document, and native Word.Interop for the rest. The code compiles nicely, but when I run it, I get an error saying that "Item is not a property" - when I try to call WordMailMergeFields.Item(I).
The variable "NoOfFields" is being set, so I my WordMailMergeFields is initialized correctly.
I would love to hear any suggestions.
0
Comments
-
I have exactly the same problema than you.
Item property has been removed from the Fields type after Office 2003 this is the cause of the error. In newer versions teorically we have to use the assignation like this:
WordMailMergeField := WordMailMergeFields;
I tested this in a .NET application and it works, but unfortunately NAV don't understand this because is expecting an array variable and you can not compile. I put a request to Microsoft with the problem, if they answer me I will keep you informed!!!
In the meantime if anybody else has found a solution.... :whistle:0 -
Hello,
I have a response from Microsoft, We have to pay for support in this incidence if we wan't they help us. Luckily, yesterday I was trying to advance in this feature in I found a solution.
I made the develop in a .NET Class Library in C#, basically the code is the same as in NAV, but I can use a foreach instruction to make the loop. Once deployed the dll, paste the dll on Service and RoleTailoredClient Add-Ins folder. Now in NAV I can declare a DoNet variable and call the functions in my library from NAV.
Hope it helps you!!
0 -
Use the Microsoft Office Interop in combination with the NAV Helper class.
Variables:
Name DataType Subtype
wdApp DotNet Microsoft.Office.Interop.Word.ApplicationClass.'Microsoft.Office.Interop.Word
wdDoc DotNet Microsoft.Office.Interop.Word.Document.'Microsoft.Office.Interop.Word
wdFields DotNet Microsoft.Office.Interop.Word.Fields.'Microsoft.Office.Interop.Word
wdRange DotNet Microsoft.Office.Interop.Word.Range.'Microsoft.Office.Interop.Word
WordHelper DotNet Microsoft.Dynamics.Nav.Integration.Office.Word.WordHelper.'Microsoft.Dynamics.Nav.Integration.Office
FileName Text 1024
Don't forget to set the property "RunOnClient" to Yes for all DotNet variables.
Code:
[...]
Add code to download file locally...
FileName := 'C:\MyTemplateFile.dot';
wdApp := wdApp.ApplicationClass;
wdDoc := WordHelper.CallOpen(wdApp,FileName,FALSE,FALSE);
wdDoc.Saved := TRUE;
wdDoc.Fields.Update;
wdFields := wdDoc.Fields;
wdRange := wdFields.Item(1).Result;
wdRange.Text := 'Hello World';
[...]0 -
hi,
This will work on NAS (JOB QUEUE) in NAV 2016 ?Now or Never0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

