+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    06-04-2009
    Location
    Australia
    MS-Off Ver
    Excel 2002
    Posts
    13

    Make a word bold if it starts with a particular character/string

    I need to make all words in a document that start with an A bold. Sounds simple, and conditional formatting on a cell would be the trick in excel but doesn't help mr in word.

    I figure I need a macro but have no clue in word vba and have been unable to find anything similar.

  2. #2
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Make a word bold if it starts with a particular character/string

    This is from the top of my head as I'm certainly not a word specialist.
    Code:
    Sub Macro2()
    
    Dim a As Long 'From 65 to 90 and for 97 to 122 a-z, A-Z
    
    Application.ScreenUpdating = False
    
      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      Selection.Find.Replacement.Font.Bold = True
      With Selection.Find
        .Text = "^p"
        .Replacement.Text = "^p " 'Add space as wildcards and ^p don't go together
        .Forward = True
        .Wrap = wdFindContinue
      End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    For a = 65 To 122 Step 1
    
      If a = 91 Then a = 97
      
      With Selection.Find
        .Text = " " & Chr(a)
        .Replacement.Text = " " & Chr(a)
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = True
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
      
    Next a
    
      With Selection.Find
        .Text = "^p "
        .Replacement.Text = "^p" 'Add space as wildcards and ^p don't go together
        .Forward = True
        .Wrap = wdFindContinue
      End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    Application.ScreenUpdating = True
    
    End Sub
    Only need to do the first by hand

    Edit: Added the red part later !
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Bold = True
    Last edited by rwgrietveld; 02-18-2010 at 06:35 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Make a word bold if it starts with a particular character/string

    Again, I'm not an expert on this but for complete words to become bold
    HTML Code:
    Sub MakeBold()
    
    Application.ScreenUpdating = False
    
      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting
      Selection.Find.Replacement.Font.Bold = True
      With Selection.Find
        .Text = "^p"
        .Replacement.Text = "^p " 'Add space as wildcards and ^p don't go together
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWildcards = False
      End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
      With Selection.Find
        .Text = " s* "
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchWildcards = True
      End With
      Selection.Find.Execute
      
      While Selection.Font.Bold = False
        Selection.Font.Bold = True
        Selection.Find.Execute
      Wend
    
      With Selection.Find
        .Text = "^p "
        .Replacement.Text = "^p" 'Add space as wildcards and ^p don't go together
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWildcards = False
      End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    Application.ScreenUpdating = True
    
    End Sub
    The restricton I have is that you have to start with ALL words NOT in Bold

    change .Text = " s* " where s is replaced by your character
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  4. #4
    Registered User
    Join Date
    06-04-2009
    Location
    Australia
    MS-Off Ver
    Excel 2002
    Posts
    13

    Re: Make a word bold if it starts with a particular character/string

    Thankyou, so much!

  5. #5
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,043

    Re: Make a word bold if it starts with a particular character/string

    There you go, Rico!! Thanks for sharing!
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  6. #6
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,479

    Re: Make a word bold if it starts with a particular character/string

    use find replace
    find <[A-a]*>
    check wild cards box then from format option select font/ bold replace all (or usr ctrl+b in the replace field)
    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  7. #7
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Make a word bold if it starts with a particular character/string

    Martin, Almost

    I like the approach, but with strings like Aaasasaasasaa all a's are turning Bold.

    As I'm not an expert I can't find a better answer. I hope you might.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  8. #8
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,479

    Re: Make a word bold if it starts with a particular character/string

    my mistake it should be
    <[aA]*> works with this see attached
    Attached Files Attached Files
    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  9. #9
    Forum Guru rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Make a word bold if it starts with a particular character/string

    Martin,

    What do you put in the "replace with" field (besides the bold

    and what about these strings?
    Zuidpool zuidpool
    Aarde aarde
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  10. #10
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,479

    Re: Make a word bold if it starts with a particular character/string

    works ok for me with those see attached
    Attached Images Attached Images
    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0