Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

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

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
PioneerSolutions
Asked:
PioneerSolutions
  • 2
1 Solution
 
Eric FletcherCommented:
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
 
Eric FletcherCommented:
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
 
PioneerSolutionsAuthor Commented:
Thank you. eg.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now