Bizarre table behaviour - can you explain?

J

Julian

Hi,

This is Word 2002... but I'd be surprised if it was unique to Word 2002...

Fed up with the DocumentMap not handling tables, I wrote my own outliner
that selectively shows and hides rows... worked a treat.

Then I discovered I needed some extra columns - but I've no screen estate
left, so I thought why not use a similar trick to show/hide one of a pair of
columns (well, alternate between v. small and "normal" width :)

Works OK BUT...

I only need one column of the pair at a time, so I set up a double-click
show/hide routine.

First, I hide a column by setting the font to hidden and then setting the
width to something small, then I show the other column by first setting the
width to "normal" AND ONLY THEN un-setting the font hidden attribute.

***** THE WEiRD BIT ******
What is weird is that when a previously "hidden" column is shown the text
ALWAYS appears in the "narrow" column (thereby causing the row height to go
crazy) even though I set the width first, before I unhide the text (it does
sort itself out a moment later, but it's hell on the eyes and it takes
time...)

Turning off screenupdating for the duration doesn't help, and no amount of
extra DoEvents calls or explicit repaginates will stop it... (all desperate
measures I admit...).

WHY? More to the point, can I stop it?

Thanks

Julian

PS I have just "purged" the template and reimported all modules, so I'm
confident there are no lurking corruptions...

Here's the code that does the business...

Sub toggleColumns(ByRef selDoc As Document, ByRef selCell As Cell)
Dim aCol As Column
Dim aCell As Cell

Application.ScreenUpdating = False
Set aCol = selCell.Range.Columns(1)
showHideColumn aCol:=aCol, show:=False ' First hide
a column
If selCell.ColumnIndex = scratchColIdx Then
Set aCol = selCell.Range.Rows(1).Cells(structureColIdx).Column
ElseIf selCell.ColumnIndex = structureColIdx Then
Set aCol = selCell.Range.Rows(1).Cells(scratchColIdx).Column
End If
showHideColumn aCol:=aCol, show:=True ' then show
the other one
Application.ScreenUpdating = True
End Sub


Sub showHideColumn(ByRef aCol As Column, ByVal show As Boolean)
Dim aCell As Cell
Dim oldSel As Range

If aCol Is Nothing Then Exit Sub
Set oldSel = Selection.Range
aCol.PreferredWidthType = wdPreferredWidthPoints
Select Case show
Case True
aCol.Select
aCol.PreferredWidth = InchesToPoints(3.01)
Selection.Font.Hidden = False
Case False
aCol.Select
Selection.Font.Hidden = True
aCol.PreferredWidth = InchesToPoints(0.01)
End Select
oldSel.Select
End Sub
 
R

Russ

Try using Application.ScreenRefresh after widening the column and before
unhiding the text. It does a one time refresh, unlike
Application.ScreenUpdating = True which is a more continuous refresh, once
turned on.
 
J

Julian

Hi Russ, thanks for responding... doesn't seem to make a difference...

I thought I had tried that but I did double check... ScreenUpdating off, but
with ScreenRefresh after column size change and font hidden change - no
difference.

In fact, part of the issue is that there is EXTRA screen refreshing - I
wasn't turning ScreenUpdate back on until everything had been done, so all
adjustments etc. should have been invisible.

Behaves the same in Normal, Print Layout and Outline views (code doesn't
work at all for Web Layout - can't access columns)

It's one of those things that ScreenUpdate just doesn't suppress... but I am
still baffled by the apparent irrelevance of the order of operations!
 
R

Russ

It sounds like a 'auto format of column width' function is struggling with
the unhidden text as the text reappears in the column. I no expert in
tables, but maybe there is an option to 'toggle off' auto formatting of
column width and then hard code the width to the size needed before exposing
the text? And then 'toggle on' the auto formatting.
 
J

Julian

Russ -

Your thought as good and it made me go back and check all properties I could
find that might be having an effect or fighting each other... that didn't
work! So I recorded a macro to do it to compare Word's code with mine and
discovered that what I should have been doing is directly setting the Cells
width!

Simply setting the preferred width doesn't work - it doesn't change the
width until sometime later (e.g. after macro exit - and putting the
hidden=false in a separate macro called from the first didn't help!)

I now leave Cells.PreferredWidth alone and just set Cells.width and it seems
fine...

Thanks for being someone to talk to!

Julian
 

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