Group:  Microsoft Word ยป microsoft.public.word.vba.addins
Thread: Help with word macro

Help with word macro
somebody[ at ]somewhere.com 3/25/2007 4:08:59 PM
After getting totally frustrated and not being able to find the
solution for a word macro I am trying to write, I'm back to try again.
Some of you might remember my earlier posts and I want to thank those
of you who tried to help but none of the code accomplished what I was
trying to do. I will try and explain, as best I can, what I am trying
to do. Below is a macro I recorded in Word 2007, which is the version
I am now using, that does the basic thing but I need a little, or
maybe a lot more. Please remember that I am a beginner with only a
basic understanding of writing macros so please explain any replys if
it contains code for me to try.

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "G"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

As you can see, this is simply a find and replace macro. Here is what
I need the help with. I need the code to do the following:

Move the cursor to the beginning of the document so that it searches
the entire document without me telling it to return to the beginning
and continue the search.

Be able to adjust the macro to search for multiple letters, numbers or
symbols in the same procedure. In my macro above I searched for the
letter "G" and replaced it with a blank space. I would like to be able
to adjust the macro code to find and replace any number of characters.
like "G" and "Y" just by adjusting the code.

Finally, after the search and replace has finished I would like for
the macro or another sub routine to remove all blank spaces between
all remaining characters left in the document. The exception being
that it will leave two blank spaces after any puncuation marks,
keeping the sentences seperated.

Maybe I am asking for too much, and if so, I appoligize. This has
frustated me for over two years now. Because of this I plan on, after
retireing this summer, attending school to learn how to do what I am
asking now. Thanks to all. Joe Payne
Re: Help with word macro
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 3/25/2007 8:59:19 PM
Probably no need to use code at all. Just use a Wildcard Edit>Replace

See the article "Finding and replacing characters using wildcards" at:

http://www.word.mvps.org/FAQs/General/UsingWildcards.htm


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

<somebody[ at ]somewhere.com> wrote in message
news:fj7d035drtnmc3jht7ekhjhroh26ajf7ls[ at ]4ax.com...
[Quoted Text]
> After getting totally frustrated and not being able to find the
> solution for a word macro I am trying to write, I'm back to try again.
> Some of you might remember my earlier posts and I want to thank those
> of you who tried to help but none of the code accomplished what I was
> trying to do. I will try and explain, as best I can, what I am trying
> to do. Below is a macro I recorded in Word 2007, which is the version
> I am now using, that does the basic thing but I need a little, or
> maybe a lot more. Please remember that I am a beginner with only a
> basic understanding of writing macros so please explain any replys if
> it contains code for me to try.
>
> Sub Macro1()
> '
> ' Macro1 Macro
> '
> '
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
> With Selection.Find
> .Text = "G"
> .Replacement.Text = " "
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Selection.Find.Execute Replace:=wdReplaceAll
> End Sub
>
> As you can see, this is simply a find and replace macro. Here is what
> I need the help with. I need the code to do the following:
>
> Move the cursor to the beginning of the document so that it searches
> the entire document without me telling it to return to the beginning
> and continue the search.
>
> Be able to adjust the macro to search for multiple letters, numbers or
> symbols in the same procedure. In my macro above I searched for the
> letter "G" and replaced it with a blank space. I would like to be able
> to adjust the macro code to find and replace any number of characters.
> like "G" and "Y" just by adjusting the code.
>
> Finally, after the search and replace has finished I would like for
> the macro or another sub routine to remove all blank spaces between
> all remaining characters left in the document. The exception being
> that it will leave two blank spaces after any puncuation marks,
> keeping the sentences seperated.
>
> Maybe I am asking for too much, and if so, I appoligize. This has
> frustated me for over two years now. Because of this I plan on, after
> retireing this summer, attending school to learn how to do what I am
> asking now. Thanks to all. Joe Payne


Home | Search | Terms | Imprint
Newsgroups Reader