Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Liam Gibbs Liam Gibbs is offline
external usenet poster
 
Posts: 2
Default Search-and-replace macro never works

Hello everyone,

I'm well aware that MS Word is not good with macros, but I never
realized to what extent until now. Here's the situation:

I'm trying to do a search-and-replace of my name in a certain style.
That's it.

So, when recording the macro, I do a search-and-replace, enter my name
plus a carraige return in the style "Centered". I enter nothing for
the replace field, as in I want to eliminate my name and leave
nothing. I do the search-and-replace, and it gets rid of them. End the
recording.

However, when I play the macro, it does nothing. I even get rid of the
^p, so that it's only looking for my name in the Centered style. No
love. Here's the thing. When I open up the search-and-replace dialog
box, instead of it looking for my name in Centered (i.e. I'm looking
at the criteria for the previous search), it was looking for Centered
with Border: Top (Single Solid Line, Auto, etc. etc.). Well, that's
not what I asked for. Where did it get the extra stuff? I looked at
the macro code, but I'm no expert and couldn't find anything out of
the ordinary.

What am I doing wrong? Or is this another of Microsoft's "features"?

  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman[_2_] Jay Freedman[_2_] is offline
external usenet poster
 
Posts: 59
Default Search-and-replace macro never works

Word is great with macros. What's not good is the recorder. Read the article
at http://word.mvps.org/FAQs/MacrosVBA/...ordedMacro.htm to find out
how to modify the garbage you get from the recorder so that it actually works.

In this case, the recorder has a bug that fails to record the proper
formatting for searches. The article explains what to change.

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


"Liam Gibbs" wrote:

Hello everyone,

I'm well aware that MS Word is not good with macros, but I never
realized to what extent until now. Here's the situation:

I'm trying to do a search-and-replace of my name in a certain style.
That's it.

So, when recording the macro, I do a search-and-replace, enter my name
plus a carraige return in the style "Centered". I enter nothing for
the replace field, as in I want to eliminate my name and leave
nothing. I do the search-and-replace, and it gets rid of them. End the
recording.

However, when I play the macro, it does nothing. I even get rid of the
^p, so that it's only looking for my name in the Centered style. No
love. Here's the thing. When I open up the search-and-replace dialog
box, instead of it looking for my name in Centered (i.e. I'm looking
at the criteria for the previous search), it was looking for Centered
with Border: Top (Single Solid Line, Auto, etc. etc.). Well, that's
not what I asked for. Where did it get the extra stuff? I looked at
the macro code, but I'm no expert and couldn't find anything out of
the ordinary.

What am I doing wrong? Or is this another of Microsoft's "features"?


  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Search-and-replace macro never works

There is very little wrong with the capability of VBA in Word. What it
lacks however is a proper macro recorder and trying to record Seach and
Replace Operations is one area where it is really deficient.

The following macro will do what you want:

Dim drange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="Your Name", MatchWildcards:=False,
Wrap:=wdFindStop, Forward:=True) = True
Set drange = Selection.Range
If drange.ParagraphFormat.Alignment = wdAlignParagraphCenter Then
drange.Paragraphs(1).Range.Delete
End If
Loop
End With


--
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

"Liam Gibbs" wrote in message
ups.com...
Hello everyone,

I'm well aware that MS Word is not good with macros, but I never
realized to what extent until now. Here's the situation:

I'm trying to do a search-and-replace of my name in a certain style.
That's it.

So, when recording the macro, I do a search-and-replace, enter my name
plus a carraige return in the style "Centered". I enter nothing for
the replace field, as in I want to eliminate my name and leave
nothing. I do the search-and-replace, and it gets rid of them. End the
recording.

However, when I play the macro, it does nothing. I even get rid of the
^p, so that it's only looking for my name in the Centered style. No
love. Here's the thing. When I open up the search-and-replace dialog
box, instead of it looking for my name in Centered (i.e. I'm looking
at the criteria for the previous search), it was looking for Centered
with Border: Top (Single Solid Line, Auto, etc. etc.). Well, that's
not what I asked for. Where did it get the extra stuff? I looked at
the macro code, but I'm no expert and couldn't find anything out of
the ordinary.

What am I doing wrong? Or is this another of Microsoft's "features"?



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Liam Gibbs Liam Gibbs is offline
external usenet poster
 
Posts: 2
Default Search-and-replace macro never works

Thanks for your help, everyone. I'll try this out.

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
search and replace macro genius? BobW Microsoft Word Help 1 March 3rd 06 04:40 PM
Search and Replace Jackie Formatting Long Documents 0 October 20th 05 10:23 AM
Search & Replace LY Microsoft Word Help 4 April 8th 05 05:25 PM
Search and Replace Arne Microsoft Word Help 4 April 6th 05 11:05 PM
search and replace Tweedy Microsoft Word Help 1 February 10th 05 11:30 AM


All times are GMT +1. The time now is 09:56 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"