Program works good when executing step by step only

A

Alex St-Pierre

Hi,
If I make a Ctrl-F8 at the line "For i = 1 To tbl.Rows.Count" and execute F5
thereafter, all works good. I tried to make a Ctrl-F8 only at the end of the
following code and the results is not good.
I really don't know why the result is not the same ?
Can it be a word refresh problem ??
Thanks,
Alex

Dim LargeurCol(6) As Variant
Dim LargeurCol2(100, 6) As Variant
Dim rngExcel As Excel.Range
Dim tbl As Word.Table
 
A

Alex St-Pierre

The problem is because: tbl.Rows(3).cells.count = 4 even if the tbl row
contains only 3 cells (because of merged cells) on this line. Can I write
something else to have answer = 3 ??
Thanks,
Alex

For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Rows(i).Cells.Count
Set pCell = tbl.Cell(i, j)
pCell.Width = LargeurCol2(i, R(i, j))
Next j
Next i
 
J

Jean-Guy Marcil

Alex St-Pierre was telling us:
Alex St-Pierre nous racontait que :
The problem is because: tbl.Rows(3).cells.count = 4 even if the tbl
row contains only 3 cells (because of merged cells) on this line. Can
I write something else to have answer = 3 ??
Thanks,
Alex

For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Rows(i).Cells.Count
Set pCell = tbl.Cell(i, j)
pCell.Width = LargeurCol2(i, R(i, j))
Next j
Next i

If you have merged cells, I don't think you can use table columns or rows in
your code.
You can use range columns or rows.

Try something like:

Dim myRange As Range
Dim i As Long
Dim lngCol As Long
Dim lngRow As Long

Set myRange = ActiveDocument.Tables(1).Range

With myRange
lngCol = .Columns.Count
lngRow = .Rows.Count
For i = 1 To .Cells.Count
'Some code
Next
End With


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

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