Kevin,
Problem 1 is caused by your not having anything selected, so Word has a problem with the Selection.Range command. If this is new, empty form, you can simply select the entire form. If not, then you have to go to the correct spot. What I've done is add a FormField called "DetailTable". I select the formfield, make sure it's blanked, move the selected item to the next row and then insert the table:
WITH oWord.activedocument
.formfields("DetailTable").Result = ''
.formfields("DetailTable").Select
oWord.selection.moveDown 1
.tables.add(oWord.selection.range, nRows, nCols)
ENDWITH
I've found that formfields make excellent markers. Also, tables are numbered internally by Word as they are added, which may help with Problem 2.
HTH
Barbara
>I have 2 Issues here:
>
>1. I created a small test program:
>
>oWord = CREATEOBJECT("Word.Application")
>
>WITH oWord
> .Visible = .T.
> .Documents.Add()
> .Documents(1).Tables.Add(Selection.Range,10,10)
>ENDWITH
>
>
>When VFP hits the line of code that adds the table,
>VFP hangs until I close the document. Weird!
>
>
>
>2. What I'm actually trying to do is find a way to
>programmatically select a table from within VFP.
>
>The code:
>
> oWord.ActiveDocument.Tables(1).Select()
>
>works when you know that the table you want is
>table 1, like when you use the .Tables.Add() method.
>
>What if I paste in a table from another document or
>open a document that contains multiple tables? I might
>know by looking at the document that the 3rd table on
>page 2 is the one I want, but how do I select in in code?
>
>Anyone have any help on this?