Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Bizarre table behaviour - can you explain?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Julian - 22 Jun 2007 01:31 GMT
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
Russ - 23 Jun 2007 10:11 GMT
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.

> Hi,
>
[quoted text clipped - 75 lines]
>     oldSel.Select
> End Sub

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Julian - 23 Jun 2007 10:58 GMT
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!

> Try using Application.ScreenRefresh after widening the column and before
> unhiding the text. It does a one time refresh, unlike
[quoted text clipped - 80 lines]
> >     oldSel.Select
> > End Sub
Russ - 23 Jun 2007 21:00 GMT
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.

> Hi Russ, thanks for responding... doesn't seem to make a difference...
>
[quoted text clipped - 96 lines]
>>>     oldSel.Select
>>> End Sub

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Julian - 24 Jun 2007 11:15 GMT
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

> 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
[quoted text clipped - 102 lines]
> >>>     oldSel.Select
> >>> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.