Macro - Can't Replace Para Mark in 2007 Word

M

Mike

I'm trying to record a macro that does the above replacement in addition to
another one. Here are the examples:

Trying to replace text "zzz" followed by a paragraph mark. It works when I
record, but when I run the macro there is no replacement.

Also trying to past text UNFORMATTED TEXT. This also works when recording
but not when I run the macro.

Any ideas?
 
J

Jean-Guy Marcil

Mike was telling us:
Mike nous racontait que :
I'm trying to record a macro that does the above replacement in
addition to another one. Here are the examples:

Trying to replace text "zzz" followed by a paragraph mark. It works
when I record, but when I run the macro there is no replacement.

Also trying to past text UNFORMATTED TEXT. This also works when
recording but not when I run the macro.

Any ideas?

Post your code...
 
M

Mike

Jean-Guy Marcil said:
Mike was telling us:
Mike nous racontait que :


Post your code...

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub Macro3()
'
' Macro3 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
Selection.WholeStory
Selection.Font.Name = "Arial"
Selection.Font.Size = 9
End Sub
Sub Macro4()
'
' Macro4 Macro
'
'
End Sub
Sub Macro5()
'
' Macro5 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
ActiveWindow.Close
End Sub
Sub Macro6()
'
' Macro6 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "zzz^p"
.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
 
J

Jean-Guy Marcil

Mike was telling us:
Mike nous racontait que :
'
' Macro1 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub Macro3()
'
' Macro3 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
Selection.WholeStory
Selection.Font.Name = "Arial"
Selection.Font.Size = 9
End Sub
Sub Macro4()
'
' Macro4 Macro
'
'
End Sub
Sub Macro5()
'
' Macro5 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
ActiveWindow.Close
End Sub
Sub Macro6()
'
' Macro6 Macro
'
'
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "zzz^p"
.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

You have mentioned two problems, but you posted 6 macros...
Do try to help us help you by cleaning up a bit... ;-)

In any case, you mentioned:
"
Trying to replace text "zzz" followed by a paragraph mark. It works
when I record, but when I run the macro there is no replacement.
"

What are you trying to replace "zzz¶" by?

According to your macro, you are not replacing it with anything:
"
.Text = "zzz^p"
.Replacement.Text = ""
"

As for pasting unformatted text, try this:

Selection.PasteSpecial DataType:=wdPasteText

Finally, these to pages may be useful to you:
http://word.mvps.org/faqs/macrosvba/UsingRecorder.htm
http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm
 
M

Mike

Jean-Guy Marcil said:
Mike was telling us:
Mike nous racontait que :


You have mentioned two problems, but you posted 6 macros...
Do try to help us help you by cleaning up a bit... ;-)

In any case, you mentioned:
"
Trying to replace text "zzz" followed by a paragraph mark. It works
when I record, but when I run the macro there is no replacement.
"

What are you trying to replace "zzz¶" by?

According to your macro, you are not replacing it with anything:
"
.Text = "zzz^p"
.Replacement.Text = ""
"

As for pasting unformatted text, try this:

Selection.PasteSpecial DataType:=wdPasteText

Finally, these to pages may be useful to you:
http://word.mvps.org/faqs/macrosvba/UsingRecorder.htm
http://word.mvps.org/faqs/macrosvba/ModifyRecordedMacro.htm
--
______________________________
Jean-Guy Marcil
Montreal, Canada
In each of my replacements I am replacing with null -- nothing. Sorry for
the extra code -- I'm not familiar with VB so I sent the recorded code.
 
G

Graham Mayor

In each of my replacements I am replacing with null -- nothing. Sorry for
the extra code -- I'm not familiar with VB so I sent the recorded code

The following appear to address your stated requirements

Sub Macro1()
'Paste unformatted text
On Error GoTo Oops
Selection.PasteSpecial DataType:=wdPasteText, _
Placement:=wdInLine
End
Oops:
Beep
End Sub

Sub Macro3()
'paste unformatted text and format 9 point Arial
Selection.PasteSpecial DataType:=wdPasteText, _
Placement:=wdInLine
Selection.WholeStory
Selection.Font.name = "Arial"
Selection.Font.Size = 9
End Sub

Sub Macro6()
'paste unformatted text and delete zzz followed by ¶
Selection.PasteSpecial DataType:=wdPasteText, _
Placement:=wdInLine
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "zzz^p"
.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

It might be better to give the macros more meaningful names, and you might
find http://www.gmayor.com/installing_macro.htm and
http://word.mvps.org/FAQs/Formatting/CleanWebText.htm useful.


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

Mike

Graham Mayor said:
The following appear to address your stated requirements

Sub Macro1()
'Paste unformatted text
On Error GoTo Oops
Selection.PasteSpecial DataType:=wdPasteText, _
Placement:=wdInLine
End
Oops:
Beep
End Sub

Sub Macro3()
'paste unformatted text and format 9 point Arial
Selection.PasteSpecial DataType:=wdPasteText, _
Placement:=wdInLine
Selection.WholeStory
Selection.Font.name = "Arial"
Selection.Font.Size = 9
End Sub

Sub Macro6()
'paste unformatted text and delete zzz followed by ¶
Selection.PasteSpecial DataType:=wdPasteText, _
Placement:=wdInLine
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "zzz^p"
.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

It might be better to give the macros more meaningful names, and you might
find http://www.gmayor.com/installing_macro.htm and
http://word.mvps.org/FAQs/Formatting/CleanWebText.htm useful.


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Your solution worked exactly as I needed it. Thank you very much Graham!
 

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