Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    font.hidden property, tables and code (2000)

    OK folks, here's my problem: I have a UserForm with a multiselect listbox that checks items according to whether the font.hidden property is true (-1) or false (0) for certain bookmarks in the document. I'm getting funny behaviour - for some bookmarks, the code is returning neither -1 nor 0, but 9999999. I'm sure I've read about something like this with some other attribute somewhere. I'm (pretty) sure the range within the bookmark won't ever be mixed "some hidden & some not", so what's going on here? If I try to check for 9999999 and set it to -1 when it's found, will that work?
    The range within each bookmark is some rows of a table, if this helps (code does seem to work fine on plain ol' paragraph text); oh, and the first cell in each row is formatted with a style that has outline numbering, too.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: font.hidden property, tables and code (2000)

    Word is not able to determine many formatting properties of a range if that range contains 50 paragraphs or more, so it returns wdUndefined (9999999). This return value only implies that the range contains a mixture of settings if the range is small enough; for large ranges you can't draw any conclusion from the return value wdUndefined.

    So my guess is that "some rows of a table" contain 50 paragraphs or more.

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: font.hidden property, tables and code (2000)

    Aha; thanks HansV, I didn't know that.
    Yes, I've checked the paragraphs.count for each of the bookmarked ranges in the table, and - you're right - the ones that give trouble have 70 paragraphs in them.
    So perhaps what I need to do is *not* have a bookmark that encompasses the whole range to be considered, but one that marks the start, another that marks the end, and have the code just ask about the .hidden property of the starting bookmark, then work with a range that's defined as eveything between the two?
    Heck: thinking as I type, since the first row of each range (and only the first - so at maximum 3 paragraphs, one for each cell in that row) is formatted with a specific style, maybe I should find some way to scrap the bookmarks altogether and identify the ranges according to style, and determine the .hidden property as it's applied to each occurrence of that style. Hmm...

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: font.hidden property, tables and code (2000)

    You also could check the number of paragraph in the actual range and check subsections of it as needed (temporary ranges over portions of the actual range), but your other solutions might be more maintainable in the long run.

  5. #5
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: font.hidden property, tables and code (2000)

    Yes; thanks to you both for these inputs. I think I've got a working solution now: I've added a second column to the listbox, and put in it the row number where the specified style occurs. So if the style is on rows 1, 12, and 22 (for example) the listbox has items:
    blah blah blah | 1
    more blah blah | 12
    yet more blah | 22. (etc.)
    ...Then according to whether the item is checked or not I can set rows 1-11, 12-21 or 22-.count as hidden or not hidden.
    Because I'm looking at the styles now, this will still work if users add their own "sections" to the table (which it didn't when I was relying on bookmarks).

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: font.hidden property, tables and code (2000)

    I don't have specific recommendations, but perhaps you can profit from the tips in Maximising the performance of Word tables on the Word MVP site. The second part is about handling tables in code.

    According to this article, the fastest way to process the cells of a table is to select the table and loop through its cells:

    Dim oCell As Cell
    ActiveDocument.Tables(1).Select
    For Each oCell In Selection.Cells
    ...
    Next oCell

  7. #7
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: font.hidden property, tables and code (2000)

    <P ID="edit" class=small>(Edited by jscher2000 on 16-Jul-03 15:47. [pre] and [/pre] markup added around code snippet to preserve indenting.)</P>Hi guys:
    Though the code for applying/retrieving the hidden property is now sorted, after a couple of days not working with the document I've now gone back in and found that populating the listbox in the first place is running unbelievably slowly.
    Here's an idea of the structure of the table, then I'll show the code I've got populating the listbox: can anybody see how I might make it run *way* faster?
    Table has 3 columns. All the text in cols 2 and 3 is formatted with a style called "response". In the first column, some rows have text in "Matrix 1" style (these are 'section headings' within the table), others have text in "Matrix 2" style (these are items under the headings). Matrix 1 and Matrix 2 styles are outline numbered (1, 2, 3 for Matrix 1; 1.1, 1.2 etc for Matrix 2).
    First part of the code for populating the listbox (slow running part):
    <pre>Dim iRow As Row, i As Integer, j As Integer, aRange As Range
    i = 1
    j = 1
    With ActiveDocument.Tables(1)
    For Each iRow In .Rows
    Set aRange = iRow.Cells(1).Range
    aRange.TextRetrievalMode.IncludeHiddenText = True
    If aRange.Paragraphs(1).Style = "matrix h1" Then
    LstSections.AddItem Left(aRange.Paragraphs(1).Range.Text, _
    Len(aRange.Paragraphs(1).Range.Text) - 2)
    LstSections.List(j - 1, 1) = i
    j = j + 1
    End If
    i = i + 1
    Next iRow
    '(more code to SELECT items in the list if the corresponding part
    ' of the table is not formatted as hidden text, then: )
    End With</pre>

    (Note: I'm chopping off the last two characters in each range because it's in table cells and I don't want the para mark or cell division character, etc.)

  8. #8
    New Lounger
    Join Date
    Mar 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: font.hidden property, tables and code (2000)

    Thanks HansV, I've printed off Dave Rado's article (I've found his articles to be v. useful in the past), and it looks like there's stuff I can play with here that should increase speed. There's certainly a suggestion that if I select a cell in column 1, then select the column, and work with the cells in the selection, that should be faster. I'll try some of these things out and post an update when I see what happens!
    (Unfortunately the best time for me to concentrate on this sort of stuff is on my machine at home - when *anything* runs pretty fast... but then I have to bring it all back in to work, whereupon I find out what's genuinely fast and what isn't!!)

  9. #9
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: font.hidden property, tables and code (2000)

    Don't know if it is in Dave Rado's article, but you can get the whole text from a table into a string in one fell swoop:
    myString=ActiveDocument.Tables(1).Range.Text

    You'd have end-of-cell-markers Chr(13)&Chr(7) after each cell, and additional ones at the end of each row.

    If your table is uniform (no merged/split cells), you can easily retrieve the contents of the cells (for example by splitting the string up with Split).

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •