Navigating on a Word Document

I am trying to insert some text, then insert a table, and then insert some more text into Word using the automation. The table is not inserting between the text, but directly after it. Does anybody know how to navigate in a word document so the range variable is at the end of the document? Farhan

Hy, I habe the same problem, i soved it in this way, First i but all my datas in Word like: AAA,BBB,CCC,FFF,EEE Then i use a macro, which take the datas an but it in a tabell, and now you can but (via the macro) then text i all positions you like. ------------ Best regards Alejandro Schubert

Thank you Alex for your reply. The problem I am having is not in creating or populating the table. What i can’t seem to do is position it between two paragraphs of free flow text. The first paragraph is inserting correctly. The table is also inserting correctly (after the first paragraph) and having its cells populated correctly. The problem occurs when i insert the second paragraph. This second paragraph inserts before the table when it should be inserting after. I can’t find a command that takes the range variable to a point after the table. I.e. wdRange.Text := ‘Text in paragraph 1’; wdRange.InsertAfter(‘Next Sentence in Paragraph 1’ ); wdRange := wdDoc.Sentences.Last; wdTable := wdRange.Tables.Add(wdRange,NoOfRows,NoOfColumns); FOR i := 1 TO NoOfRows DO BEGIN FOR j := 1 TO NoOfColumns DO BEGIN wdCell := wdTable.Cell(i,j); wdRange := wdCell.Range; wdRange.Text := ‘Text In Cell’; END; END; At this point everything is fine. However, no matter what i try, I can’t position my second paragraph to start after the table. I am looking for a way to make my wdRange variable start at the very last position in the document (like the wdRange := wdDoc.Sentences.Last; statement, but for a document). Farhan

Hello. I don’t know if this works (at the moment I can not try it myself), but maybe you can solve the problem bij sending some [RETURN]'s to the Word document,just before you add the second paragraph. Like this: Variables: char ch ch:=13; wdRange.Text := FORMAT(cr); Anolis Sittard Netherlands

Farhan, The expression you are looking is called MoveStart. Use it in this way: Selection.MoveStart Unit:=wdTable, Count:=1 Units can also be characters, words, sentences, paragraphs etc. See the VB Help for details. John

Thank you all for your help. I had managed to solve the problem by inserting two paragraphs on first creating the document. This way, by moving to the last sentence, I am always at the last point in the document. I have now changed my code to the MoveStart function - cheers John. Farhan

John: What is the exact syntax of “Selection.MoveStart Unit:=wdTable, Count:=1”. When I type it that way I get a syntax error. Regards Uwe

Uwe, You should add a reference to the Word document. See the previous messages of this thread for sample syntax. John Edited by - John Tegelaar on 11/6/00 10:04:05 PM

John: I´ve read this posting but there are still a reasonable number of ???´s. I think the object “Select” is a little bit mysterious when adressed from NAVISION. In a plain VBA-makro I can define: bookmark(“mybookmark”).select selection.text = “mytext” If I try this out of NAVISION this way: WordDoc := WordDocs.Add ( TemplateName ); WordBookmarks := WordDoc.Bookmarks; s := ‘Name3’; WordBookmarks.Item ( s ).Select; s := ‘“aaaaaaaaaaaaaaaa”’; WordSelection.Text := s; ← causes error message I receive an error message: “This Automation variable was not instantiated …” Translated from german. Do you have an idea? Regards Uwe

Uwe, It looks like you’re not really familiar with the concept of accessing Word, or Excel. (Is that what you call Office Automation?) Believe to have a set of samples (from Navision) at the office that should provide you the insight. Will mail these to you. 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í