Help with word macro

S

somebody

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
 
H

Helmut Weber

Hi,

this is what you've got:
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:

This is what you get, according to your description.

Asyoucansee, thisissimplyafindandreplacemacro. Hereiswhat
Ineedthehelpwith. Ineedthecodetodothefollowing:

That is not what you want, I assume.
But what is it then?

Sub Test400()
Dim rngDcm As Range
Set rngDcm = ActiveDocument.Range
With rngDcm.Find
.Text = "[GY]{1,}"
.Replacement.Text = " "
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
.Text = "[ ]{1,}"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
.Text = "([:;\.\,\!\?]){1}"
.Replacement.Text = "\1 "
.Execute Replace:=wdReplaceAll
End With
End Sub

See:
http://word.mvps.org/faqs/general/UsingWildcards.htm
http://www.gmayor.com/replace_using_wildcards.htm

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Doug Robbins - Word MVP

See responses in other newsgroups to which you posted this question.

Please do not post the same question separately to multiple newsgroups.

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

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