Automation and MS Word

Hi all: I know Word automation has been discussed many times here. However, my VBA experience is very limited, and the examples in the ADG (which I’ve read) and others here do more than I need or want, and I’d like to take a “baby step” in making this work. I don’t seem to be able to locate a reference for Word that I can loook for the specific methods required to accomplish a task, so I’m asking your help in either (a) giving an example that meets my requirements, or (b) pointing me to a good “simple” reference. I have a Word document that is a product information sheet - unique for each item in the Navision item table. The document path and name is stored in a field in the Navision item table, e.g. ‘e:\documents\Item10005.doc’ When I print invoices, I want to also print a copy of the Word document aassociated with the item. One complexity here. I’m assuming that if you are printing an invoice with several lines, that if you call automation after line 1 in the report, it will “immediately” start printing, e.g. the MS Word printing will interrupt the invoice report. So, if I have multiple line items on the report, do I have to loop through the Sales Invoice Line dataitem a second time and print all the documents at the end? Any suggestions here? Thanks in advance to all. Ron

Ron, Here’s how to get a reference to a Word object. 1) You have to have MS-Word installed on the client 2) Add a variable to your code unit of type Automation (must have the OCX granule to do this) 3) In the subtype for the variable, click the lookup button 4) On the Automation Object List Window, click the lookup button in the Automation Sever text box 5) This brings up the Automation Server List Window, page down until you locate Microsoft Word 9.0 Object Library. Double click to select it. (Note this is MS-Word 2000, I believe MS-Word97 is version 8.0) 6) This takes you back to the Automation Object List Window which now list all the objects available for MS-Word. Someone else will have to help with your other questions. Hope this helps, Bill

Hi, be sure to have the Word VBA (Visual Basic for Applications) help file installed (doesn’t install by default). There you find everything of documentation you need. As an introduction try this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2kta/html/offaut.asp Roger Edited by - RogerH on 2002 Mar 27 17:16:11

Thanks to both of you for replying - all other suggestions - keep coming, with my thanks. Ron

I suggest you look at Attain’s contact management to see how that interfaces with word. Pay attention to Codeunit 5054. Word will only print when you call the print method so you can pour as you like into the document. There are no rules about how you should print it but I would develop a seperate codeunit to print the word document and call that from the invoice report. This is just to keep things seperate and tidy. Paul Baxter

Suggestion: instead of looping through Sales Invoice Dataitem a second time - use a temporary Item table. That is, a Item Record-type variable with the Property Temporary=Yes. As you go along you can insert the Sales Invoice Items to this record, and at the end loop through the entire temporary table to get the Items you have used (you can use an Integer dataitem for this). Nikolai L’Estrange Developer

Navision as a whole with Automation is not that good. I have been working hard to Integrate Navision and Excel better (I know your looking at Word). One of the problems I have found with Navision is that in some instances it can Refence the same Class/Object twice in the Word/Excel collection which is confusing because you think you have specified two diffrent objects. Such as Application and Document. If you are going to advance your navision Automation could I suggest a book called Word 2000 VBA by Wrox, its about £17.00GBP. You might not want to use VBA but it contains the whole Object Model from word which is what you are accessing, and has a better set of help than that of Attain. If you want any more help dont hesitate to contact me Cheers Tony Edited by - tonyh on 2002 Mar 28 10:48:10

The VBA help files of word, excel and outlook have their object models in and extensive documentation about the object the properties and methods. most of the books I have found are basicly just reprints of this information. Paul Baxter

Maybe you should take a look at the book before making such a generic refrence to “all” books. I personally found that the help files in VBA can be sometimes as difficult as the ones in Navision. Also the book I refer to gives good examples on use of the methods with in the classes that have helped me no end. After all I am not a VBA developer but will use VBA for to acheive what navision have told me their automation controller cannot do. Regards Tony

Thsnks for all the comments, especially Tony. The reference to the book was especially helpful. I, too, have problems looking at Microsoft help - it never seems to have enough at the “primer” level, e.g. examples of the simplest usage of a command. Let me walk before I can run, and I’ll come up to speed quickly. Regards, Ron

Thanks to all. I’ve created my function to print the document from Word - and it works! Ron

Moved from “Attain/Financials Developer Forum” to “Attain/Financials Developer FAQ”.