I'm automating Word in a VB6 application and I'm getting an exception when the host machine is using Word 2007 or 2010 but not on a machine running Word 2003. The exception is
Runtime error '4605': "This method or property is not available because the object refers >to the end of a table row."
The exception is thrown on the seventh iteration of the following loop, on the line which attempts to insert a page break:
For num = 1 To breakArrCount
Set myRange = oworddoc.Paragraphs(breakArr(num)).Range
With myRange
On Error Resume Next
.Collapse Direction:=wdCollapseEnd
.InsertBreak Type:=wdPageBreak
End With
Next
The array, breakArr, stores the indexes of the paragraphs in the document which are to be followed by a page break.
Interestingly enough, if I break out of the loop prior to the exception (i.e. after the 6th iteration) and view the generated document, I notice that the page breaks (for the first 6 pages) are inserted in different points in Word 2007/2010 than in 2003.
Why would there be a difference? Does anybody know what I should be doing differently?
Thanks.