Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Feb 2014
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How to delete all of the "normal" text in a table cell without deleting bold or [] text?

    I have a Word table and would like to delete all of the "normal" text in the cells and leave all text that is bold or surrounded by brackets, []

    For example:

    This is the text I want to delete. I want to keep this text. I want to delete this text. [Keeping this text] [Keep this too] Keep this. Delete this.


    Not all of the bold or [] text are complete sentences. The text between the brackets will not be bold. Some of the bold text will be symbols or Wingdings.

    Thanks for your help!!

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,945
    Thanks
    0
    Thanked 203 Times in 184 Posts
    You can do this in four steps:
    1. Format all of the text as hidden.
    2. Find all text between brackets and format as not hidden.
    3. Find all bold text and format as not hidden.
    4. Find & delete all hidden text.

    For example:
    Code:
    Sub Demo()
    Application.ScreenUpdating = False
    With ActiveDocument.Tables(1).Range
      .Font.Hidden = True
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .Font.Bold = True
        .MatchWildcards = True
        .Text = ""
        .Replacement.Text = "^&"
        .Replacement.Font.Hidden = False
        .Execute Replace:=wdReplaceAll
        .ClearFormatting
        .Text = "\[*\]"
        .Execute Replace:=wdReplaceAll
        .Replacement.ClearFormatting
        .Font.Hidden = True
        .Text = ""
        .Replacement.Text = ""
        .Execute Replace:=wdReplaceAll
      End With
    End With
    Application.ScreenUpdating = True
    End Sub
    Last edited by macropod; 2014-02-10 at 04:47.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,534
    Thanks
    3
    Thanked 147 Times in 140 Posts
    I would do a series of search and replace
    Find Bold and make it highlighted
    Find \[*\] with wildcards and make it highlighted
    Find anything not highlighted and delete it
    remove the highlight
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    New Lounger
    Join Date
    Feb 2014
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I think I can create the code to find and highlight. Can you give me an example to find "not highlighted" and delete? Many thanks!

  5. #5
    New Lounger
    Join Date
    Feb 2014
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts
    For the ActiveDocument.Tables(1).Range example - I'm really sorry but this did not work for me. My table simply disappeared. I would love to understand more to trouble shoot. Is there a place where all of the text codes are listed (e.g. ^&). I think the row by row change would be better for me as a starting point. Also is there a book you recommend for learning the basics?

  6. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,945
    Thanks
    0
    Thanked 203 Times in 184 Posts
    The code isn't deleting the table, just leaving its borders formatted as hidden. Try adding:
    .Font.Hidden = False
    between
    End With
    End With
    and changing:
    With .Find
    to:
    With .Duplicate.Find

    Alternatively, insert:
    ActiveDocument.Tables(1).Range.Font.Hidden = False
    after:
    End With
    End With
    Last edited by macropod; 2014-02-10 at 16:08.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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