Solved

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

Posted on 2009-05-04
3
376 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
ID: 24297488
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
ID: 24297496
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
ID: 31577644
Thank you. eg.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
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 …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

911 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

22 Experts available now in Live!

Get 1:1 Help Now