Table resize stepping/running code

B

Bart Hernalsteen

Hi all,

I have the following problem : I resize the columns of a table that I have
created in the same macro.

When I run my code step by step (F8) It works
When I execute it it does not resize my columns.

I'm working with Word XP on Windows Xp.

Here's my code

' Define the range for the table
Set rngTable = ActiveDocument.Range(Start:=lngStart, End:=lngEnd)
' Convert the text to table
Set tblTable = rngTable.ConvertToTable(Separator:=wdSeparateByTabs,
AutoFitBehavior:=wdAutoFitFixed)

' Set the columnwidth for each column. The widths are stored in the
first Row
lngColumns = tblTable.Columns.Count
For intCount = 1 To lngColumns
dblWidth = Val(tblTable.Cell(1, intCount).Range.Text)
If dblWidth > 0 Then
tblTable.Columns(intCount).PreferredWidthType =
wdPreferredWidthPoints
tblTable.Columns(intCount).PreferredWidth =
CentimetersToPoints(dblWidth)
End If
Next intCount

Application.ScreenRefresh
DoEvents

I tried DoEvents and application.screenrefresh. No solution.

Can anyone help me ?
Thanks in advance

Bart
 
W

Word Heretic

G'day "Bart Hernalsteen" <[email protected]>,

this generic sort of problem is usually fixed by either a DoEvents to
let the document holder thingy do its thing, or, in this case very
tricky but possible, use of the OnTime command to delay execution.


Bart Hernalsteen said:
Hi all,

I have the following problem : I resize the columns of a table that I have
created in the same macro.

When I run my code step by step (F8) It works
When I execute it it does not resize my columns.

I'm working with Word XP on Windows Xp.

Here's my code

' Define the range for the table
Set rngTable = ActiveDocument.Range(Start:=lngStart, End:=lngEnd)
' Convert the text to table
Set tblTable = rngTable.ConvertToTable(Separator:=wdSeparateByTabs,
AutoFitBehavior:=wdAutoFitFixed)

' Set the columnwidth for each column. The widths are stored in the
first Row
lngColumns = tblTable.Columns.Count
For intCount = 1 To lngColumns
dblWidth = Val(tblTable.Cell(1, intCount).Range.Text)
If dblWidth > 0 Then
tblTable.Columns(intCount).PreferredWidthType =
wdPreferredWidthPoints
tblTable.Columns(intCount).PreferredWidth =
CentimetersToPoints(dblWidth)
End If
Next intCount

Application.ScreenRefresh
DoEvents

I tried DoEvents and application.screenrefresh. No solution.

Can anyone help me ?
Thanks in advance

Bart

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email: (e-mail address removed)
Products: http://www.geocities.com/word_heretic/products.html
Spellbooks: 728 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.
 

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