Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Replace Styles on Empty Cells (2002 XP)

    Does anyone know how to use Find and Replace on an empty cell to change the style?

    I suspect that this has some relationship to this thread on searching for styles in tables, but has anyone seen a way to replace the style of an empty cell without cycling through all the cells?

    Your classic replace style macro, e.g.
    <pre> With ChangeDocument.Content.Find
    .ClearFormatting
    .Style = OldStyle
    .Replacement.ClearFormatting
    .Replacement.Style = NewStyle
    .Execute Format:=True, findtext:="", replacewith:="", Replace:=wdReplaceAll
    End With
    </pre>

    doesn't change a table cell that's got nothing in it.
    My clients are asking to be able to remove 'foreign' styles from their documents, so this is critical.
    What's truly nasty is that if you then delete the 'foreign' style while it's still attached to those cells, rather than them reverting to "Normal" as a paragraph would, there's no style object attached to those ranges/cells/paragraphs at all! This gets even worse when, in trying to fix it (by looking for no style object on a paragraph), you can't force a style to the 'paragraph' that is the end-of-row marker.

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

    Re: Replace Styles on Empty Cells (2002 XP)

    Duplicating the .Execute line takes care of all cells for me. I only tested on a small document, though, so make sure to do your own testing.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace Styles on Empty Cells (2002 XP)

    Y'know, of all the options, doing it *AGAIN* never occured to me.
    It seems to take multiple passes for some messier tables, so I'm going
    while .Execute(blahblah)
    DoEvents
    wend

    Thanks much
    Joel

    p.s. My first attempt at this ran on infinitely, stepping through it, it didn't... I may not have solved it yet. Will let you folks know.

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

    Re: Replace Styles on Empty Cells (2002 XP)

    BTW, if you have, say, 2 vertically merged cells, the styles list might still still show style that had been applied to lower merged cell before they were merged as "in use", although the cell shows the style of the previous upper cell.
    If you split the merged cell again, the style gets applied to the lower cell again.
    It's a bug (or a strange feature) that you probably can't do much about :-(

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

  5. #5
    2 Star Lounger
    Join Date
    Jan 2004
    Location
    Mount Prospect, Illinois
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Replace Styles on Empty Cells (2002 XP)

    Another weird side-effect: if the document isn't visible, Word's range.find won't find the empty cells at all. Much better results occur if the document is visible at least for a short period of time. Rendering it to the screen must have some side effect on the internal data structures.

    It causes an unfortunate blink, but
    oDoc.windows.Add
    oDoc.windows(1).visible = false
    does the trick.

Posting Permissions

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