Run time error 5843

A

Alex St-Pierre

Hello,
I have a lot of error message in my programmation that does not happen when
I execute my program step by step with F8. I never encoutered this kind of
problem with excel vba. As example, in my table, I have 3 columns for each
row except for row #3 that contains only 2 columns. When I execute the macro,
it stop at this line:
Tables(1).Cell(3, 1).Borders(wdBorderTop).LineWidth = wdLineWidth025pt
giving the runtime error message 5843 (out limits). When this happens, I put
the cursor on line before and then, when click on F8 2 times, all works good.
Does anyone know why this happens ?
Thanks !
Alex

For i = 1 To 10
For j = 1 To Tables(1).Rows(i).Cells.Count
Tables(1).Cell(i, j).Borders(wdBorderTop).LineStyle =
wdLineStyleSingle
Tables(1).Cell(i, j).Borders(wdBorderTop).LineWidth =
wdLineWidth025pt
Next j
Next i
 
A

Alex St-Pierre

Just before the error happens, the value of c seems to be the problem.

Tables(1).Cell(i, j).Borders(wdBorderTop).LineStyle = wdLineStyleSingle
c = Tables(1).Cell(3, 1).Borders(wdBorderTo).LineWidth ' c takes value
-2079342459
Tables(1).Cell(3, 1).Borders(wdBorderTo).LineWidth = wdLineWidth025pt
 
J

Jean-Guy Marcil

Alex St-Pierre was telling us:
Alex St-Pierre nous racontait que :
Hello,
I have a lot of error message in my programmation that does not
happen when I execute my program step by step with F8. I never
encoutered this kind of problem with excel vba. As example, in my
table, I have 3 columns for each row except for row #3 that contains
only 2 columns. When I execute the macro, it stop at this line:
Tables(1).Cell(3, 1).Borders(wdBorderTop).LineWidth = wdLineWidth025pt
giving the runtime error message 5843 (out limits). When this
happens, I put the cursor on line before and then, when click on F8 2
times, all works good. Does anyone know why this happens ?
Thanks !
Alex

For i = 1 To 10
For j = 1 To Tables(1).Rows(i).Cells.Count
Tables(1).Cell(i, j).Borders(wdBorderTop).LineStyle =
wdLineStyleSingle
Tables(1).Cell(i, j).Borders(wdBorderTop).LineWidth =
wdLineWidth025pt
Next j
Next i

Since the end result is a top order on every row, why not use this instead?

For i = 1 To 10
With Tables(1).Rows(i).Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth025pt
End With
Next i

I tried your code as posted on a table with a merged cell in the third row
as you described and it ran fine with F8 or F5.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

Alex St-Pierre

Hi Jean-Guy,
All works good when you create a table in Word. When you create it in Excel
and copy it to word, I found a bug in Word when you copy it using "Rtf:=True"
option.
I shown how to reproduce the bug in issue: ("How to count the cells in a
table Row") - You will see that Ctrl-F8 and F5 doesn't give the same answer
in a very basic example.. After doing this example, if you tried to copy the
table to word using Rtf:=False, all works good !

I think this problem is related to the same bug because when I format the
table step by step, all works good (as in the example in the other issue).
Maybe I will have to post this bug to Microsoft ?

Merci bcp!
 

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