macro problems

  • Thread starter Stephen Larivee
  • Start date
S

Stephen Larivee

I have a long document in Word 2003. I need to do extensive formating in
sections of the file. I selected the text and then created a macro. I did
my formating moves which involved Find and Replace and said, No, I did not
want to do the rest of the document. I finished and saved the macro.

Now, I select some other text and then run the macro. But it keeps doing
the entire text, not just the selected text.

What am I doing wrong? How do I get the macro to stay with the selected
text only????
 
J

Jay Freedman

I have a long document in Word 2003. I need to do extensive formating in
sections of the file. I selected the text and then created a macro. I did
my formating moves which involved Find and Replace and said, No, I did not
want to do the rest of the document. I finished and saved the macro.

Now, I select some other text and then run the macro. But it keeps doing
the entire text, not just the selected text.

What am I doing wrong? How do I get the macro to stay with the selected
text only????

Look at the code of the macro (select the macro in the Tools > Macro >
Macros dialog and click the Edit button). Somewhere in the mess is a
line that starts with ".Wrap =" followed by a word. If that word is
wdFindContinue, try changing it to wdFindStop.

If that doesn't fix it, post the code in the body of a reply in this
thread.
 
S

Stephen Larivee

I tried replacing all of the wdFindContinue with wdFindStop but the problem
continues.

CleanPartial Macro
' Macro recorded 1/25/2005 by Stephen Larivee
'
Selection.WholeStory
Selection.Font.Name = "Times New Roman"
Selection.Font.Size = 12
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ">"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "~"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = " ^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p "
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "'"
.Replacement.Text = "'"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = """"
.Replacement.Text = """"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p^p^p"
.Replacement.Text = "^p^p"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "~~~~"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "~~~~"
.Replacement.Text = "^p^p"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = " "
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
 
G

Graham Mayor

The problem is with the first line of your macro - selection.whole story.
Remove that line.

There are several bits of your macro that are unnecessary and some bits that
don't do anything. You could also reduce the number of steps by using
wildcards http://www.gmayor.com/replace_using_wildcards.htm - and get rid
of all of it by using the stripmail utility linked from the downloads page
of my web site - but to tidy up your code to what I think you intended:

Sub CleanPartial()
' Macro recorded 1/25/2005 by Stephen Larivee
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Font.Name = "Times New Roman"
.Font.Size = 12
.Text = ">"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
With Selection.Find
.Text = "~"
.Replacement.Text = ""
End With
Selection.Find.Execute replace:=wdReplaceAll
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
End With
Selection.Find.Execute replace:=wdReplaceAll
With Selection.Find
.Text = " ^p"
.Replacement.Text = "^p"
End With
Selection.Find.Execute replace:=wdReplaceAll
With Selection.Find
.Text = "^p "
.Replacement.Text = "^p"
End With
Selection.Find.Execute replace:=wdReplaceAll

'**********************************************
'what is this section supposed to be doing?
With Selection.Find
.Text = "'"
.Replacement.Text = "'"
End With
Selection.Find.Execute replace:=wdReplaceAll

'and this

With Selection.Find
.Text = """"
.Replacement.Text = """"
End With
Selection.Find.Execute replace:=wdReplaceAll
'**************************************************

With Selection.Find
.Text = "^p^p^p"
.Replacement.Text = "^p^p"
End With
Selection.Find.Execute replace:=wdReplaceAll
With Selection.Find
.Text = "^p^p"
.Replacement.Text = "~~~~"
End With
Selection.Find.Execute replace:=wdReplaceAll
With Selection.Find
.Text = "^p"
.Replacement.Text = " "
End With
Selection.Find.Execute replace:=wdReplaceAll
With Selection.Find
.Text = "~~~~"
.Replacement.Text = "^p^p"
End With
Selection.Find.Execute replace:=wdReplaceAll
With Selection.Find
.Text = " "
.Replacement.Text = " "
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jay Freedman

Thanks for stepping in, Graham. You're at least 5 hours ahead of me (are you
back in the UK now, or still in Cyprus?).

I think the section you commented with
'what is this section supposed to be doing?
will change all straight single and double quotes to curly (aka "smart")
quotes, assuming that option is set.
 
G

Graham Mayor

I'm currently in the UK - I am off to Ireland next week (so won't be around
for a few days) then back to Cyprus (permanently) on May 17th.

As for the curly quotes I think I would have used autoformat to effect that,
but I have left the original code intact.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Stephen Larivee

Thank you. I will give this a try. I will also look at the strip mail
utility at your web site.

Thanks again.
 

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