Reconize 2 characters

S

Steved

Hello from Steved

J( 2 0 0) the macro is ok to bold

Hr(14 2 2) what do I add to the macro please to catch the Hr to bold

Sub RaceBaseBold()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[A-Z]\([0-9 ]{2,}\)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Replacement.Text = ""
.Replacement.Font.Size = "8"
.Replacement.Font.Bold = True
Selection.Find.Execute Replace:=wdReplaceAll
End With
End Sub
Thankyou.
 
H

Helmut Weber

Hi Steve,

not quite simple.
I'm assuming, that you want all characters
before the first parenthesis to be bold,
and that there is no other text,
to which the definition in the search patterns would apply.

Sub RaceBaseBold2()
Dim rDcm As Range
Dim rTmp As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "[A-Za-z]{1,}\([0-9 ]{2,}\)"
.MatchWildcards = True
While .Execute
Set rTmp = rDcm
With rTmp.Find
.Text = "[A-Za-z]{1,}"
If .Execute Then
rTmp.Font.Bold = True
End If
End With
rDcm.Collapse direction:=wdCollapseEnd
rDcm.End = ActiveDocument.Range.End
.Text = "[A-Za-z]{1,}\([0-9 ]{2,}\)"
Wend
End With
ResetSearch
End Sub

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub


Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
S

Steved

Hello Helmut,

Once again thankyou it is exactly as you have put it together.

Cheers.
 
S

Steved

Hello Helmut from Steved

parenthesis bold to ) ie J( 2 0 0) Hr(14 2 2)

would you be so kind please to extend your macro to acheive the above

Thankyou.
 
H

Helmut Weber

Hi Steve,

like this:

Sub RaceBaseBold3()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "[A-Za-z]{1,}\([0-9 ]{2,}\)"
.MatchWildcards = True
While .Execute
With rDcm.Find
.Text = "[A-Za-z]{1,}\("
If .Execute Then
rDcm.Font.Bold = True
End If
.Text = "\)"
rDcm.Collapse direction:=wdCollapseEnd
rDcm.End = ActiveDocument.Range.End
If .Execute Then
rDcm.Font.Bold = True
End If
End With
rDcm.Collapse direction:=wdCollapseEnd
rDcm.End = ActiveDocument.Range.End
.Text = "[A-Za-z]{1,}\([0-9 ]{2,}\)"
Wend
End With
ResetSearch
End Sub

Note, that I have omitted the temporary range rTmp,
as it isn't required. One could even think of developing
a recursive procedure, for searching in the result of
a search. But that's another story.

Beware of typos ";" (German) vs. "," (International)
in the search-patterns.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
S

Steved

Sorry Helmut can you adjust your macro to bold between ( ) please so the end
result would be your macro bolds everything ie J( 2 0 0), Hr(14 2 2)

Thankyou.

Steved said:
Thanks Helmut Have a good day.

Cheers

Helmut Weber said:
Hi Steve,

like this:

Sub RaceBaseBold3()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "[A-Za-z]{1,}\([0-9 ]{2,}\)"
.MatchWildcards = True
While .Execute
With rDcm.Find
.Text = "[A-Za-z]{1,}\("
If .Execute Then
rDcm.Font.Bold = True
End If
.Text = "\)"
rDcm.Collapse direction:=wdCollapseEnd
rDcm.End = ActiveDocument.Range.End
If .Execute Then
rDcm.Font.Bold = True
End If
End With
rDcm.Collapse direction:=wdCollapseEnd
rDcm.End = ActiveDocument.Range.End
.Text = "[A-Za-z]{1,}\([0-9 ]{2,}\)"
Wend
End With
ResetSearch
End Sub

Note, that I have omitted the temporary range rTmp,
as it isn't required. One could even think of developing
a recursive procedure, for searching in the result of
a search. But that's another story.

Beware of typos ";" (German) vs. "," (International)
in the search-patterns.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
H

Helmut Weber

Hi Steve,

like this, and in some other ways:

Sub RaceBaseBold0()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "[A-Za-z]{1,}\([0-9 ]{2,}\)"
.MatchWildcards = True
While .Execute
rDcm.Font.Bold = True
Wend
End With
ResetSearch
End Sub


Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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