Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Wed, 14 May 2008 03:59:14 -0700,    group: microsoft.public.word.vba.beginners        back       


Underlining problem   
I use Word XP.  I want to find an UNDERLINED and CAPITALIZED " P. " and replace it with " P " without underlining.  Then
I want to clear out the underlining on the numbers that precede and follow the "P" (This relates to legal citations, in case
anybody is interested.  

Here is the macro.  It worked when I recorded it, but I'm afraid to run it on another document, because I cannot see where it
specifies UNDERLINING.  

Can somebody help me?


Lady Dungeness
Out of Danger until September
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~


-------------------------
Sub Macro10()
'
' Macro10 Macro
' Macro recorded 5/14/2008 by Normal
'
     Selection.Find.ClearFormatting
     Selection.Find.Replacement.ClearFormatting
     Selection.Find.Replacement.Style = ActiveDocument.Styles( _
          "Default Paragraph Font")
     With Selection.Find
          .Text = " P. "
          .Replacement.Text = " P "
          .Forward = True
          .Wrap = wdFindContinue
          .Format = True
          .MatchCase = True
          .MatchWholeWord = False
          .MatchByte = False
          .MatchAllWordForms = False
          .MatchSoundsLike = False
          .MatchWildcards = False
          .MatchFuzzy = False
     End With
     Selection.Find.Execute Replace:=wdReplaceAll
End Sub
---------------------------------
date: Wed, 14 May 2008 03:59:14 -0700   author:   unknown

Re: Underlining problem   
Don't be afraid.

Save the document before you run it.  If it doesn't do what you want, close 
the document without saving it and then open it again.  Or, use Undo.

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

 wrote in message 
news:ubhl24lf7r7bdtep5vr6jv3da3con0cro3@4ax.com...
> I use Word XP.  I want to find an UNDERLINED and CAPITALIZED " P. " and 
> replace it with " P " without underlining.  Then
> I want to clear out the underlining on the numbers that precede and follow 
> the "P" (This relates to legal citations, in case
> anybody is interested.
>
> Here is the macro.  It worked when I recorded it, but I'm afraid to run it 
> on another document, because I cannot see where it
> specifies UNDERLINING.
>
> Can somebody help me?
>
>
> Lady Dungeness
> Out of Danger until September
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
>
>
> -------------------------
> Sub Macro10()
> '
> ' Macro10 Macro
> ' Macro recorded 5/14/2008 by Normal
> '
>     Selection.Find.ClearFormatting
>     Selection.Find.Replacement.ClearFormatting
>     Selection.Find.Replacement.Style = ActiveDocument.Styles( _
>          "Default Paragraph Font")
>     With Selection.Find
>          .Text = " P. "
>          .Replacement.Text = " P "
>          .Forward = True
>          .Wrap = wdFindContinue
>          .Format = True
>          .MatchCase = True
>          .MatchWholeWord = False
>          .MatchByte = False
>          .MatchAllWordForms = False
>          .MatchSoundsLike = False
>          .MatchWildcards = False
>          .MatchFuzzy = False
>     End With
>     Selection.Find.Execute Replace:=wdReplaceAll
> End Sub
> ---------------------------------
date: Wed, 14 May 2008 21:37:40 +1000   author:   Doug Robbins - Word MVP

Re: Underlining problem   
You're correct that there's nothing about underlining in the recorded macro. 
That's because the macroi recorder in Word 97 through 2003 has a bug 
(finally fixed in Word 2007) that fails to record any kind of formatting in 
a Find operation, although it does record ".Format = True". Read the "Fixing 
broken Replace macros" section of 
http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm. The fix for 
that is to insert the line

  .Font.Underline = wdUnderlineSingle

in the list of things under "With Selection.Find".

However, that won't entirely solve the problem, because it can't remove the 
underlining from the numbers before and after the "P" (since you never 
"find" the numbers, only the "P"). The complete fix is to use a wildcard 
search (http://www.gmayor.com/replace_using_wildcards.htm) instead of a 
regular search. To record this, click the More button in the Find dialog and 
check the "Use wildcards" box. In the Find What box, paste in

([0-9]{1,}) P. ([0-9]{1,})

In the Replace With box, paste in

\1 P \2

and click Replace All. You'll still have to go into the recorded macro and 
add the .Font.Underline statement.

-- 
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so 
all may benefit.

LadyDungeness@Fish.Net wrote:
> I use Word XP.  I want to find an UNDERLINED and CAPITALIZED " P. "
> and replace it with " P " without underlining.  Then
> I want to clear out the underlining on the numbers that precede and
> follow the "P" (This relates to legal citations, in case anybody is
> interested.
>
> Here is the macro.  It worked when I recorded it, but I'm afraid to
> run it on another document, because I cannot see where it specifies
> UNDERLINING.
>
> Can somebody help me?
>
>
> Lady Dungeness
> Out of Danger until September
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
>
>
> -------------------------
> Sub Macro10()
> '
> ' Macro10 Macro
> ' Macro recorded 5/14/2008 by Normal
> '
>     Selection.Find.ClearFormatting
>     Selection.Find.Replacement.ClearFormatting
>     Selection.Find.Replacement.Style = ActiveDocument.Styles( _
>          "Default Paragraph Font")
>     With Selection.Find
>          .Text = " P. "
>          .Replacement.Text = " P "
>          .Forward = True
>          .Wrap = wdFindContinue
>          .Format = True
>          .MatchCase = True
>          .MatchWholeWord = False
>          .MatchByte = False
>          .MatchAllWordForms = False
>          .MatchSoundsLike = False
>          .MatchWildcards = False
>          .MatchFuzzy = False
>     End With
>     Selection.Find.Execute Replace:=wdReplaceAll
> End Sub
> ---------------------------------
date: Wed, 14 May 2008 11:24:27 -0400   author:   Jay Freedman

Re: Underlining problem   
This is very helpful.  It explains why some of my Macro efforts weren't working -- not all mty fault!  I'll fiddle with the
underlining and the wildcards.   


Lady Dungeness
Out of Danger until September
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~


On Wed, 14 May 2008 11:24:27 -0400, "Jay Freedman"  wrote:

>You're correct that there's nothing about underlining in the recorded macro. 
>That's because the macroi recorder in Word 97 through 2003 has a bug 
>(finally fixed in Word 2007) that fails to record any kind of formatting in 
>a Find operation, although it does record ".Format = True". Read the "Fixing 
>broken Replace macros" section of 
>http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm. The fix for 
>that is to insert the line
>
>  .Font.Underline = wdUnderlineSingle
>
>in the list of things under "With Selection.Find".
>
>However, that won't entirely solve the problem, because it can't remove the 
>underlining from the numbers before and after the "P" (since you never 
>"find" the numbers, only the "P"). The complete fix is to use a wildcard 
>search (http://www.gmayor.com/replace_using_wildcards.htm) instead of a 
>regular search. To record this, click the More button in the Find dialog and 
>check the "Use wildcards" box. In the Find What box, paste in
>
>([0-9]{1,}) P. ([0-9]{1,})
>
>In the Replace With box, paste in
>
>\1 P \2
>
>and click Replace All. You'll still have to go into the recorded macro and 
>add the .Font.Underline statement.
date: Wed, 14 May 2008 09:01:01 -0700   author:   unknown

Re: Underlining problem   
...
I'm afraid to
> run it on another document, because I cannot see where it specifies
> UNDERLINING.
>
> Can somebody help me?

I believe clearformatting removes the underline and everything else 
format-wise.  So if there is other formatting (not capitalization, etc., 
but literally formating) it'll also remove those of course.  Haven't 
scripted in really long time but I think if you check the clear 
formatting commands in Help it'll explain that.
   I dont' think it'll be an issue with citations unless maybe it messes 
up the line numbers, so check those too; you might need to except them 
somehow.

As for testing a macro/vba/etc, always copy a document, or a portion of 
the document if it's a large one, to another similar filename first. 
e.g. If it's lawn.odt, make the other file lawn-testing.odt or 
lawn_macro.odt;  something like that.
   By keeping the name and just adding to the end of it it, you also 
keep it near its original in directory/folder listings.
   Then you can hack/play all you want without worrying about damaging 
the original.
   When everything works, just transfer the macro to a full copy of the 
original, and if that works, go ahead with whatever you'd like to do 
with all of them.

Beware; September approacheth < G >

Regards,

Twayne

>
>
> Lady Dungeness
> Out of Danger until September
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
>
>
> -------------------------
> Sub Macro10()
> '
> ' Macro10 Macro
> ' Macro recorded 5/14/2008 by Normal
> '
>     Selection.Find.ClearFormatting
>     Selection.Find.Replacement.ClearFormatting
>     Selection.Find.Replacement.Style = ActiveDocument.Styles( _
>          "Default Paragraph Font")
>     With Selection.Find
>          .Text = " P. "
>          .Replacement.Text = " P "
>          .Forward = True
>          .Wrap = wdFindContinue
>          .Format = True
>          .MatchCase = True
>          .MatchWholeWord = False
>          .MatchByte = False
>          .MatchAllWordForms = False
>          .MatchSoundsLike = False
>          .MatchWildcards = False
>          .MatchFuzzy = False
>     End With
>     Selection.Find.Execute Replace:=wdReplaceAll
> End Sub
> ---------------------------------
date: Thu, 22 May 2008 13:43:54 -0400   author:   Twayne

Re: Underlining problem   
Hi Twayne,

>I believe clearformatting removes the underline and everything else 
>format-wise.  So if there is other formatting (not capitalization, etc., 
>but literally formating) it'll also remove those of course.

No, it doesn't work that way.

The .Find.ClearFormatting doesn't have any effect at all on the text in the
document. It affects only the set of formatting settings that the .Find object
looks for during the search. It's equivalent to putting the cursor in the Find
What box of the Replace dialog and clicking the "No Formatting" button (at the
bottom of the dialog after the More button is clicked).

The .Find.Replacement.ClearFormatting removes any formatting settings that might
be left over from a previous replacement. It's equivalent to putting the cursor
in the Replace With box of the Replace dialog and clicking the "No Formatting"
button. If you find bold text and replace with text that has no formatting
settings, it will stay bold -- to change the text's format, you'd have to mark
the replacement as Not Bold (or .Find.Replacement.Bold = False in a macro).

Good practice in macro programming is to start every search or replacement by
doing ClearFormatting on both the .Find and the .Find.Replacement so you start
from a known base; and then specify the formatting for the search and for the
replacement explicitly.

Your advice about testing on a copy of the document and not on the original is
spot on.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

On Thu, 22 May 2008 13:43:54 -0400, "Twayne"  wrote:

>...
>I'm afraid to
>> run it on another document, because I cannot see where it specifies
>> UNDERLINING.
>>
>> Can somebody help me?
>
>I believe clearformatting removes the underline and everything else 
>format-wise.  So if there is other formatting (not capitalization, etc., 
>but literally formating) it'll also remove those of course.  Haven't 
>scripted in really long time but I think if you check the clear 
>formatting commands in Help it'll explain that.
>   I dont' think it'll be an issue with citations unless maybe it messes 
>up the line numbers, so check those too; you might need to except them 
>somehow.
>
>As for testing a macro/vba/etc, always copy a document, or a portion of 
>the document if it's a large one, to another similar filename first. 
>e.g. If it's lawn.odt, make the other file lawn-testing.odt or 
>lawn_macro.odt;  something like that.
>   By keeping the name and just adding to the end of it it, you also 
>keep it near its original in directory/folder listings.
>   Then you can hack/play all you want without worrying about damaging 
>the original.
>   When everything works, just transfer the macro to a full copy of the 
>original, and if that works, go ahead with whatever you'd like to do 
>with all of them.
>
>Beware; September approacheth < G >
>
>Regards,
>
>Twayne
>
>>
>>
>> Lady Dungeness
>> Out of Danger until September
>> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
>>
>>
>> -------------------------
>> Sub Macro10()
>> '
>> ' Macro10 Macro
>> ' Macro recorded 5/14/2008 by Normal
>> '
>>     Selection.Find.ClearFormatting
>>     Selection.Find.Replacement.ClearFormatting
>>     Selection.Find.Replacement.Style = ActiveDocument.Styles( _
>>          "Default Paragraph Font")
>>     With Selection.Find
>>          .Text = " P. "
>>          .Replacement.Text = " P "
>>          .Forward = True
>>          .Wrap = wdFindContinue
>>          .Format = True
>>          .MatchCase = True
>>          .MatchWholeWord = False
>>          .MatchByte = False
>>          .MatchAllWordForms = False
>>          .MatchSoundsLike = False
>>          .MatchWildcards = False
>>          .MatchFuzzy = False
>>     End With
>>     Selection.Find.Execute Replace:=wdReplaceAll
>> End Sub
>> ---------------------------------
>
>
date: Thu, 22 May 2008 19:48:13 -0400   author:   Jay Freedman

Re: Underlining problem   
Ouch!  Thanks for the catch on that.  Apologies to all.

Twayne


> Hi Twayne,
>
>> I believe clearformatting removes the underline and everything else
>> format-wise.  So if there is other formatting (not capitalization,
>> etc., but literally formating) it'll also remove those of course.
>
> No, it doesn't work that way.
>
> The .Find.ClearFormatting doesn't have any effect at all on the text
> in the document. It affects only the set of formatting settings that
> the .Find object looks for during the search. It's equivalent to
> putting the cursor in the Find What box of the Replace dialog and
> clicking the "No Formatting" button (at the bottom of the dialog
> after the More button is clicked).
>
> The .Find.Replacement.ClearFormatting removes any formatting settings
> that might be left over from a previous replacement. It's equivalent
> to putting the cursor in the Replace With box of the Replace dialog
> and clicking the "No Formatting" button. If you find bold text and
> replace with text that has no formatting settings, it will stay bold
> -- to change the text's format, you'd have to mark the replacement as
> Not Bold (or .Find.Replacement.Bold = False in a macro).
>
> Good practice in macro programming is to start every search or
> replacement by doing ClearFormatting on both the .Find and the
> .Find.Replacement so you start from a known base; and then specify
> the formatting for the search and for the replacement explicitly.
>
> Your advice about testing on a copy of the document and not on the
> original is spot on.
>
>
>> ...
>> I'm afraid to
>>> run it on another document, because I cannot see where it specifies
>>> UNDERLINING.
>>>
>>> Can somebody help me?
>>
>> I believe clearformatting removes the underline and everything else
>> format-wise.  So if there is other formatting (not capitalization,
>> etc., but literally formating) it'll also remove those of course.
>> Haven't scripted in really long time but I think if you check the
>> clear formatting commands in Help it'll explain that.
>>   I dont' think it'll be an issue with citations unless maybe it
>> messes up the line numbers, so check those too; you might need to
>> except them somehow.
>>
>> As for testing a macro/vba/etc, always copy a document, or a portion
>> of the document if it's a large one, to another similar filename
>> first. e.g. If it's lawn.odt, make the other file lawn-testing.odt or
>> lawn_macro.odt;  something like that.
>>   By keeping the name and just adding to the end of it it, you also
>> keep it near its original in directory/folder listings.
>>   Then you can hack/play all you want without worrying about damaging
>> the original.
>>   When everything works, just transfer the macro to a full copy of
>> the original, and if that works, go ahead with whatever you'd like
>> to do with all of them.
>>
>> Beware; September approacheth < G >
>>
>> Regards,
>>
>> Twayne
>>
>>>
>>>
>>> Lady Dungeness
>>> Out of Danger until September
>>> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
>>>
>>>
>>> -------------------------
>>> Sub Macro10()
>>> '
>>> ' Macro10 Macro
>>> ' Macro recorded 5/14/2008 by Normal
>>> '
>>>     Selection.Find.ClearFormatting
>>>     Selection.Find.Replacement.ClearFormatting
>>>     Selection.Find.Replacement.Style = ActiveDocument.Styles( _
>>>          "Default Paragraph Font")
>>>     With Selection.Find
>>>          .Text = " P. "
>>>          .Replacement.Text = " P "
>>>          .Forward = True
>>>          .Wrap = wdFindContinue
>>>          .Format = True
>>>          .MatchCase = True
>>>          .MatchWholeWord = False
>>>          .MatchByte = False
>>>          .MatchAllWordForms = False
>>>          .MatchSoundsLike = False
>>>          .MatchWildcards = False
>>>          .MatchFuzzy = False
>>>     End With
>>>     Selection.Find.Execute Replace:=wdReplaceAll
>>> End Sub
>>> ---------------------------------
date: Fri, 23 May 2008 12:20:01 -0400   author:   Twayne

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us