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. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,877
    Thanks
    0
    Thanked 182 Times in 167 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 03:47.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,510
    Thanks
    3
    Thanked 143 Times in 136 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

  5. #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!

  6. #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?

  7. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,877
    Thanks
    0
    Thanked 182 Times in 167 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 15: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
  •