Solved

VBA code to bold all text occuring between two strings in a Word Table

Posted on 2009-05-04
3
375 Views
Last Modified: 2013-11-25
Hi,
We need some VBA code to loop through cells in a Word Table and bold all text that falls between the following two strings respectively: "||" and ">>" (without removing the delimiters.)
For a quick preview see:
http://www.eligreen.com/share/Bold_String_Pattern.pdf
The code should work on the attached file. Please see.
Thank you
eg
Bold-String-Pattern.doc
0
Comment
Question by:PioneerSolutions
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
EricFletcher earned 500 total points
Comment Utility
The wildcard pattern I suggested for your earlier question can easily be modified to keep the delimiters. When I posted it, I assumed (incorrectly) that you wanted the delimiters removed as well. This does what you want on the file you posted.
Sub SetBold()

    With Selection.Find

        .ClearFormatting

        .Replacement.ClearFormatting

        .Replacement.Font.Bold = True

        .Text = "(|| )(*)( \>\>)"

        .Replacement.Text = "\1\2\3"

        .MatchWildcards = True

        .Execute Replace:=wdReplaceAll, Format:=True, Forward:=True

    End With

End Sub

Open in new window

0
 
LVL 21

Expert Comment

by:EricFletcher
Comment Utility
The wildcard pattern I suggested for your earlier question can easily be modified to keep the delimiters. When I posted it, I assumed (incorrectly) that you wanted the delimiters removed as well. This does what you want on the file you posted.
Sub SetBold()

    With Selection.Find

        .ClearFormatting

        .Replacement.ClearFormatting

        .Replacement.Font.Bold = True

        .Text = "(|| )(*)( \>\>)"

        .Replacement.Text = "\1\2\3"

        .MatchWildcards = True

        .Execute Replace:=wdReplaceAll, Format:=True, Forward:=True

    End With

End Sub

Open in new window

0
 

Author Closing Comment

by:PioneerSolutions
Comment Utility
Thank you. eg.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now