Using templates in MS word

Hello! I’ve got the following problem. I want to use a document template in MS Word. (MS Word 2000) The following code shows how I do that: Template:=‘C:\Program Files…etc.’; CREATE(wdApplication); wdDocument:=wdApplication.Documents.Add(Template); wdApplication.ActiveDocument.Fields.Update; wdApplication.Visible:=TRUE; wdRange:=wdApplication.ActiveDocument.Fields.Item(1).Result; wdRange.Text:=‘Item one’; wdRange:=wdApplication.ActiveDocument.Fields.Item(2).Result; wdRange.Text:=‘Item two’; wdRange:=wdApplication.ActiveDocument.Fields.Item(3).Result; wdRange.Text:=‘Item three’; wdRange:=wdApplication.ActiveDocument.Fields.Item(4).Result; wdRange.Text:=‘Item four’; …etc. This works. But there is one problem. The template I use contains some prefixed text. (Text like “Type your company name here”). My code just adds the text to this. What I want is to replace the prefixed text, without changing the template. Has anyone done this before? If so: how did you do it? Thanks. Anolis Sittard Netherlands

You must leave this prefixed fieles skiped. wdRange:=wdApplication.ActiveDocument.Fields.Item(1).Result; wdRange.Text:=‘Item one’; wdRange:=wdApplication.ActiveDocument.Fields.Item(3).Result; wdRange.Text:=‘Item two’; wdRange:=wdApplication.ActiveDocument.Fields.Item(4).Result; wdRange.Text:=‘Item three’; wdRange:=wdApplication.ActiveDocument.Fields.Item(5).Result; wdRange.Text:=‘Item four’; …etc. now the second field is your prefixed :wink: ------------ Best regards Alejandro Schubert alejandro.schubert@cycos.com

Hmmm, I’m afraid I don’t realy get it. Anolis Sittard Netherlands

Did you try to Select the field, then insert new text (= overwrite it)? John

Yes, I tried, and no, it doesn’t work. Anolis Sittard Netherlands

Looked up the VB Help for the formfields TextInput property. The solution is simpler than you thought. In Dutch (hi, Anolis) it says: Met de eigenschap Result voor het object FormField kunt u de inhoud van een TextInput-object opvragen of instellen. ActiveDocument.FormFields(“Tekst1”).Result = “Jan Jansen” For the others, this translates as: With the property Result for the object FormField you can set or retrieve the content of a TextInput-object. ActiveDocument.FormFields(“Text1”).Result = “John Doe” Good luck. John

-------------------------------------------------------------------------------- Hy, In MSDN you can obtain more examples to acces Word, but in Navision you must create each word object, and then use this functions and properties. ex. wordRange := wordApl.ActiveDocument.Fields.Item(‘direction’).Result; wordRange.Text := FORMAT(“direction”); and later wordApl.ActiveDocument.Fields.Unlink; to hide fields not used in Word. Agustí

Hmmm, still no luck. The only thing that works is making changes to the template. The template I am using (Professionele Brief ltr.dot, in dutch) uses 6 Macro Buttons and 2 AutoTextLists. Actually I don’t know anything about these things (never worked with Word Macros), but I guess FormFields are something else. When I try the following: wdApplication.ActiveDocument.FormFields(“Tekst1”).Result = “Jan Jansen”. I get all sorts of errors. I tried it many different ways, with always one og the following results: 1. Navision doesn’t accept the syntaxis or variables I enter. 2. When Navision does accept it, MS Word doesn’t. Lucky for me it isn’t too hard to change the template: I can simply remove the unwanted text in the template. Maybe it’s a good idear to make a Navision add-on that creates Word templates during runtime? Anolis Sittard Netherlands