Find and Replace mystery

M

Maria

I'm using the following Find & Replace to find in a
paragraph the next phrase or sentence that ends in a
question mark or period. I then want to place that
phrase or sentence inside brackets with bold formatting.

While testing the following entries directly in the Find
and Replace dialog box, it works perfectly! However,
when I record a macro with the very same keystrokes,
everything except the bold formatting appears correctly.
Here's what I use.

FIND: (<*)([\?.]) Font: Not Bold, Not Italic;
REPLACE:[\1\2] Font: Bold
Use Wildcards

I've tried it with no mention of formatting in the Find
box and then using bold in the Replace, and that hasn't
worked either.

I'm sure there's a simple answer to this, but I don't
know what it is.

Thanks a million for the many times you've "kicked me up
a notch" as a word processor!

Maria
 
J

Jay Freedman

Hi, Maria,

Compare your recorded macro to this hand-built one, which works:

Sub BoldAndBracketSentence()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True

.Text = "(<*)([\?.])"
.Font.Bold = False
.Font.Italic = False
.Replacement.Text = "[\1\2]"
.Replacement.Font.Bold = True

.Execute Replace:=wdReplaceOne
End With

Selection.Collapse wdCollapseEnd
End Sub

Maria said:
I'm using the following Find & Replace to find in a
paragraph the next phrase or sentence that ends in a
question mark or period. I then want to place that
phrase or sentence inside brackets with bold formatting.

While testing the following entries directly in the Find
and Replace dialog box, it works perfectly! However,
when I record a macro with the very same keystrokes,
everything except the bold formatting appears correctly.
Here's what I use.

FIND: (<*)([\?.]) Font: Not Bold, Not Italic;
REPLACE:[\1\2] Font: Bold
Use Wildcards

I've tried it with no mention of formatting in the Find
box and then using bold in the Replace, and that hasn't
worked either.

I'm sure there's a simple answer to this, but I don't
know what it is.

Thanks a million for the many times you've "kicked me up
a notch" as a word processor!

Maria
 
M

Maria

Hi, Jay,

Thanks for coming through, AGAIN!

Maria
Fort Lauderdale, Florida
-----Original Message-----
Hi, Maria,

Compare your recorded macro to this hand-built one, which works:

Sub BoldAndBracketSentence()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True

.Text = "(<*)([\?.])"
.Font.Bold = False
.Font.Italic = False
.Replacement.Text = "[\1\2]"
.Replacement.Font.Bold = True

.Execute Replace:=wdReplaceOne
End With

Selection.Collapse wdCollapseEnd
End Sub

Maria said:
I'm using the following Find & Replace to find in a
paragraph the next phrase or sentence that ends in a
question mark or period. I then want to place that
phrase or sentence inside brackets with bold formatting.

While testing the following entries directly in the Find
and Replace dialog box, it works perfectly! However,
when I record a macro with the very same keystrokes,
everything except the bold formatting appears correctly.
Here's what I use.

FIND: (<*)([\?.]) Font: Not Bold, Not Italic;
REPLACE:[\1\2] Font: Bold
Use Wildcards

I've tried it with no mention of formatting in the Find
box and then using bold in the Replace, and that hasn't
worked either.

I'm sure there's a simple answer to this, but I don't
know what it is.

Thanks a million for the many times you've "kicked me up
a notch" as a word processor!

Maria


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word
.
 
M

Maria

Hi,Jay,

Now that your most useful BoldAndBracketSentence is in
place and working great, could you tell me how to edit(or
rewrite)the macro so that it will bold and bracket the
PREVIOUS sentence instead of the one FOLLOWING the
cursor?

Also, Jay, I'm inhibited as far as trying edits on
macros. Is it possible to do something stupid that would
cause big trouble not only with that macro but all others
on my computer?

Jay, thanks for your help, the extent of which you
couldn't imagine!

Maria

-----Original Message-----
Hi, Maria,

Compare your recorded macro to this hand-built one, which works:

Sub BoldAndBracketSentence()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True

.Text = "(<*)([\?.])"
.Font.Bold = False
.Font.Italic = False
.Replacement.Text = "[\1\2]"
.Replacement.Font.Bold = True

.Execute Replace:=wdReplaceOne
End With

Selection.Collapse wdCollapseEnd
End Sub

Maria said:
I'm using the following Find & Replace to find in a
paragraph the next phrase or sentence that ends in a
question mark or period. I then want to place that
phrase or sentence inside brackets with bold formatting.

While testing the following entries directly in the Find
and Replace dialog box, it works perfectly! However,
when I record a macro with the very same keystrokes,
everything except the bold formatting appears correctly.
Here's what I use.

FIND: (<*)([\?.]) Font: Not Bold, Not Italic;
REPLACE:[\1\2] Font: Bold
Use Wildcards

I've tried it with no mention of formatting in the Find
box and then using bold in the Replace, and that hasn't
worked either.

I'm sure there's a simple answer to this, but I don't
know what it is.

Thanks a million for the many times you've "kicked me up
a notch" as a word processor!

Maria


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word
.
 
J

Jay Freedman

Hi, Maria,

Working on the previous sentence is a bit nastier problem than going
forward. Here's one solution (other approaches are possible):

Sub BoldAndBracketPrevSentence()
Dim oRg As Range
Set oRg = Selection.Range

With oRg.Find
.ClearFormatting
.Format = False
.Forward = False
.Wrap = wdFindStop
.MatchWildcards = True

.Text = "([\?.] {1,})(<*)([\?.])"

If .Execute Then
oRg.MoveStartWhile cset:="?. "
oRg.Text = "[" & oRg.Text & "]"
oRg.Font.Bold = True
End If
End With
End Sub

It's highly unlikely that anything you do to one macro will damage
other macros -- you'd have to be messing with macros that use the VBA
Extensibility Library to change the macro codes, which is a fairly
advanced subject. If you're still wary, just make a new template and
do your editing there until you know the macro works properly; if you
mess up, you can just delete the template. While you're testing
macros, of course, always work on a *copy* of any document that has
value, keeping the original out of harm's way.

Maria said:
Hi,Jay,

Now that your most useful BoldAndBracketSentence is in
place and working great, could you tell me how to edit(or
rewrite)the macro so that it will bold and bracket the
PREVIOUS sentence instead of the one FOLLOWING the
cursor?

Also, Jay, I'm inhibited as far as trying edits on
macros. Is it possible to do something stupid that would
cause big trouble not only with that macro but all others
on my computer?

Jay, thanks for your help, the extent of which you
couldn't imagine!

Maria

-----Original Message-----
Hi, Maria,

Compare your recorded macro to this hand-built one, which works:

Sub BoldAndBracketSentence()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True

.Text = "(<*)([\?.])"
.Font.Bold = False
.Font.Italic = False
.Replacement.Text = "[\1\2]"
.Replacement.Font.Bold = True

.Execute Replace:=wdReplaceOne
End With

Selection.Collapse wdCollapseEnd
End Sub

Maria said:
I'm using the following Find & Replace to find in a
paragraph the next phrase or sentence that ends in a
question mark or period. I then want to place that
phrase or sentence inside brackets with bold formatting.

While testing the following entries directly in the Find
and Replace dialog box, it works perfectly! However,
when I record a macro with the very same keystrokes,
everything except the bold formatting appears correctly.
Here's what I use.

FIND: (<*)([\?.]) Font: Not Bold, Not Italic;
REPLACE:[\1\2] Font: Bold
Use Wildcards

I've tried it with no mention of formatting in the Find
box and then using bold in the Replace, and that hasn't
worked either.

I'm sure there's a simple answer to this, but I don't
know what it is.

Thanks a million for the many times you've "kicked me up
a notch" as a word processor!

Maria
 
M

Maria

Thanks a million, Jay!
-----Original Message-----
Hi, Maria,

Working on the previous sentence is a bit nastier problem than going
forward. Here's one solution (other approaches are possible):

Sub BoldAndBracketPrevSentence()
Dim oRg As Range
Set oRg = Selection.Range

With oRg.Find
.ClearFormatting
.Format = False
.Forward = False
.Wrap = wdFindStop
.MatchWildcards = True

.Text = "([\?.] {1,})(<*)([\?.])"

If .Execute Then
oRg.MoveStartWhile cset:="?. "
oRg.Text = "[" & oRg.Text & "]"
oRg.Font.Bold = True
End If
End With
End Sub

It's highly unlikely that anything you do to one macro will damage
other macros -- you'd have to be messing with macros that use the VBA
Extensibility Library to change the macro codes, which is a fairly
advanced subject. If you're still wary, just make a new template and
do your editing there until you know the macro works properly; if you
mess up, you can just delete the template. While you're testing
macros, of course, always work on a *copy* of any document that has
value, keeping the original out of harm's way.

Maria said:
Hi,Jay,

Now that your most useful BoldAndBracketSentence is in
place and working great, could you tell me how to edit (or
rewrite)the macro so that it will bold and bracket the
PREVIOUS sentence instead of the one FOLLOWING the
cursor?

Also, Jay, I'm inhibited as far as trying edits on
macros. Is it possible to do something stupid that would
cause big trouble not only with that macro but all others
on my computer?

Jay, thanks for your help, the extent of which you
couldn't imagine!

Maria

-----Original Message-----
Hi, Maria,

Compare your recorded macro to this hand-built one, which works:

Sub BoldAndBracketSentence()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = True
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True

.Text = "(<*)([\?.])"
.Font.Bold = False
.Font.Italic = False
.Replacement.Text = "[\1\2]"
.Replacement.Font.Bold = True

.Execute Replace:=wdReplaceOne
End With

Selection.Collapse wdCollapseEnd
End Sub


I'm using the following Find & Replace to find in a
paragraph the next phrase or sentence that ends in a
question mark or period. I then want to place that
phrase or sentence inside brackets with bold formatting.

While testing the following entries directly in the Find
and Replace dialog box, it works perfectly! However,
when I record a macro with the very same keystrokes,
everything except the bold formatting appears correctly.
Here's what I use.

FIND: (<*)([\?.]) Font: Not Bold, Not Italic;
REPLACE:[\1\2] Font: Bold
Use Wildcards

I've tried it with no mention of formatting in the Find
box and then using bold in the Replace, and that hasn't
worked either.

I'm sure there's a simple answer to this, but I don't
know what it is.

Thanks a million for the many times you've "kicked me up
a notch" as a word processor!

Maria


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word
.
 

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