Timing Issue??

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
 
G

Greg Maxey

Manfred,

No I haven't. Actually problem occurs during the creation of new documents
from a template. It never happens on my PC. I can ask the lady seeing the
problem if she can open and repair the template and see if tht helps.

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
 
M

Manfred F

Hi Greg,

You can also check the template by opening and repairing. Sometimes this
leads to a real surprise.
If only one single pc behaves weird, one should also consider
reinstallation. I once had problems with add-ins on just one pc, which
disappeared after reinstalling windows and office..

Regards,

Manfred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top