Solved

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

Posted on 2009-05-04
3
377 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

777 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