G
Greg Maxey
I am seeing some odd behavior in a piece of code.
I have a table in a document with five rows:
Sub Demo()
Dim oTbl as Word.Table
Set oTbl = ActiveDocument.Tables(1)
With oTbl
.Rows(3).Height = 1
.Rows(3).HeightRule = wdRowHeightExactly
.Rows(4).Height = 1
.Rows(4).HeightRule = wdRowHeightExactly
End With
End Sub
On most machines the above code runs without error. On some machines the
code throws an error:
"Run-Time error '4605' The Height method or property is not available
because some or all of the object does not refer to a table."
On this line:
..Rows(3).Height = 1
The error is not thrown if I step through the code manually.
I can also mask the error with code like this (awful I know)
Sub Demo()
Dim oTbl as Word.Table
Set oTbl = ActiveDocument.Tables(1)
On Error Resume Next 'Added
With oTbl
.Rows(3).Height = 1 'Added
.Rows(3).Height = 1
.Rows(3).HeightRule = wdRowHeightExactly
.Rows(4).Height = 1
.Rows(4).HeightRule = wdRowHeightExactly
End With
On Error GoTo 0
End Sub
The code seems perfectly content to continue with the same line of code
after it has slowed down a bit to handler the error.
I was thinking this must be some timing issue. Is this something that
DoEvents might help eliminate? If so can someone advise where I should put
DoEvents in my code.
Thanks.
--
Greg Maxey
See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.
"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR
I have a table in a document with five rows:
Sub Demo()
Dim oTbl as Word.Table
Set oTbl = ActiveDocument.Tables(1)
With oTbl
.Rows(3).Height = 1
.Rows(3).HeightRule = wdRowHeightExactly
.Rows(4).Height = 1
.Rows(4).HeightRule = wdRowHeightExactly
End With
End Sub
On most machines the above code runs without error. On some machines the
code throws an error:
"Run-Time error '4605' The Height method or property is not available
because some or all of the object does not refer to a table."
On this line:
..Rows(3).Height = 1
The error is not thrown if I step through the code manually.
I can also mask the error with code like this (awful I know)
Sub Demo()
Dim oTbl as Word.Table
Set oTbl = ActiveDocument.Tables(1)
On Error Resume Next 'Added
With oTbl
.Rows(3).Height = 1 'Added
.Rows(3).Height = 1
.Rows(3).HeightRule = wdRowHeightExactly
.Rows(4).Height = 1
.Rows(4).HeightRule = wdRowHeightExactly
End With
On Error GoTo 0
End Sub
The code seems perfectly content to continue with the same line of code
after it has slowed down a bit to handler the error.
I was thinking this must be some timing issue. Is this something that
DoEvents might help eliminate? If so can someone advise where I should put
DoEvents in my code.
Thanks.
--
Greg Maxey
See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.
"It is not the critic who counts, not the man who points out how the strong
man stumbles, or where the doer of deeds could have done them better. The
credit belongs to the man in the arena, whose face is marred by dust and
sweat and blood, who strives valiantly...who knows the great enthusiasms,
the great devotions, who spends himself in a worthy cause, who at the best
knows in the end the triumph of high achievement, and who at the worst, if
he fails, at least fails while daring greatly, so that his place shall never
be with those cold and timid souls who have never known neither victory nor
defeat." - TR