How can I make all text "[" and "]" and Bold?

S

Sukhi

Hi
I have range object, which will contain something like --
[You must] read the later sections starting ['What you might get… '] to see
the important notes about these figures and the [assumptions] we’ve made.

I want all text within [] make bold and get rid of []s. If [] have special
meaning then I can change them with "//" in database. I have tried following
from another post (thanks to Helmut Weber) --

Sub test10()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "/*/"
.MatchWildcards = True
While .Execute
rDcm.Start = rDcm.Start + 1
rDcm.End = rDcm.End - 1
' for testing in single step mode only [F8]
rDcm.Select ' delete after testing
rDcm.Font.Bold = True
rDcm.Start = rDcm.End + 1
rDcm.End = ActiveDocument.Range.End
Wend
End With
End Sub

Above works with // but not with [], still I need to delete //s.

Could some one please help, need this sorting soon
 
G

Greg

Suhki,

If I understand correctly, you want words/phrases inside brackets to be
bolded and the brackets removed.

If correct, try:

Sub test10()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "(\[)(*)(\])"
.MatchWildcards = True
.Replacement.Text = "\2"
.Replacement.Font.Bold = True
.Execute Replace:=wdReplaceAll
End With
End Sub
 
S

Sukhi

Thanks Greg
That is exactly what I wanted to do
-- What does "\2" means
..Replacement.Text = "\2"
 
G

Graham Mayor

Actually you only need the middle set of brackets then replace with \1 ;)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Greg

You mean the middle set of parens "(*)" i.e., "\[(*)\]"
and replace with "\1"

Agreed ;-)
 

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