• Replace Styles on Empty Cells (2002 XP)

    Author
    Topic
    #417945

    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.

        With ChangeDocument.Content.Find
            .ClearFormatting
            .Style = OldStyle
            .Replacement.ClearFormatting
            .Replacement.Style = NewStyle
            .Execute Format:=True, findtext:="", replacewith:="", Replace:=wdReplaceAll
        End With
    

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #939156

      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.

      • #939163

        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.

        • #939974

          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 🙁

          cheers Klaus

        • #939987

          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.

    Viewing 0 reply threads
    Reply To: Replace Styles on Empty Cells (2002 XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: