Programatically change some words enclosed in tokens to bold

E

eksabik

Hi,
I have a document with some words enclosed between #BE# and #EN#, an example
would be: sometext#BE#wordtochange#EN#sometext#BE#wordtochange#EN#sometext....
..

I need to change the words between #BE# and #EN# to words in bold, and
ideally remove those tokens.

Can anybody help me?
 
R

rhamre

Sub Example()

Application.ScreenUpdating = False

Dim rng As Range
Set rng = ActiveDocument.Range

With rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "#[BE]{2}#(*)#[EN]{2}#"
.Replacement.Text = " \1 "
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With

End Sub

Hope that helps.
 
E

eksabik via OfficeKB.com

Thank you rhamre for your code. It works and is what I was looking for.

As a beginner in programming vb with word objects I want you to explain me,
if possible, what is the meaning of the quote enclosed part of the .Text and .
Replacement line.


Regards

Sub Example()

Application.ScreenUpdating = False

Dim rng As Range
Set rng = ActiveDocument.Range

With rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "#[BE]{2}#(*)#[EN]{2}#"
.Replacement.Text = " \1 "
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With

End Sub

Hope that helps.
Hi,
I have a document with some words enclosed between #BE# and #EN#, an example
[quoted text clipped - 5 lines]
Can anybody help me?
 
G

Graham Mayor

See http://www.gmayor.com/replace_using_wildcards.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Thank you rhamre for your code. It works and is what I was looking
for.

As a beginner in programming vb with word objects I want you to
explain me, if possible, what is the meaning of the quote enclosed
part of the .Text and . Replacement line.


Regards

Sub Example()

Application.ScreenUpdating = False

Dim rng As Range
Set rng = ActiveDocument.Range

With rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "#[BE]{2}#(*)#[EN]{2}#"
.Replacement.Text = " \1 "
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With

End Sub

Hope that helps.
Hi,
I have a document with some words enclosed between #BE# and #EN#,
an example
[quoted text clipped - 5 lines]
Can anybody help me?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top