Macro won't work...

  • Thread starter Thread starter silas
  • Start date Start date
S

silas

Hi. I following the steps to create a macro to paste unformatted text. I
start the recorder, go to Edit, Paste Special and select Unformatted Text. I
stop the recorder and save the macro in Normal.dot. However, every time I
run it I still get formatted text.

Here's the Visual Basic code:

Sub PasteSpec()
'
' PasteSpec Macro
' Macro recorded 8/29/2007 by me
'
Selection.PasteAndFormat (wdPasteDefault)
End Sub

What am I doing wrong?

Thanks

silas
 
(wdpastedefault) picks up the formatting of the source. You can change the
code to:

Sub PasteSpec()
Selection.PasteAndFormat(wdFormatPlainText)
End Sub
 
Thanks Harvey, that code works.

I still don't understand why the steps I followed created a macro to paste
source formatting when I specifically selected Paste Special> Unformatted
Text. Could this be the result of a virus?

silas
 
Macro recorder doesn't alway generate the best possible code so sometimes we
to to combine the recorded code with our experence and programming knowledge
to produce the best code. In your example we can use the following code which
uses pastespecial method instead of pasteAndFormat method

Sub PasteSpec()
Selection.PasteSpecial datatype:=wdPasteText
End Sub
so the short answer to your question. No , thsi behavor is not caused by a
virus, as i said before althoug macrorecorder is an extreamly valuebale tool
in our hands but we must remember it's not 100% reliable all the times!
 
Hi. I following the steps to create a macro to paste unformatted text. I
start the recorder, go to Edit, Paste Special and select Unformatted Text. I
stop the recorder and save the macro in Normal.dot. However, every time I
run it I still get formatted text.

Here's the Visual Basic code:

Sub PasteSpec()
'
' PasteSpec Macro
' Macro recorded 8/29/2007 by me
'
Selection.PasteAndFormat (wdPasteDefault)
End Sub

What am I doing wrong?

Thanks

silas


I know this post will probably never get read since this is so long
ago, but I have run into the exact same thing with Word 2003. Word
2000 and below worked fine. It must be one of those infamous MS bugs
they tend to do a lot of the time, then never fix.
 
You are correct: it doesn't work. One of the problems with the Macro
Recorder is that often recorded macros are full of bloated bumpf and just
don't work. Even this simple Paste as Unformatted Text you tried to record
is defeated! (Note that I used this very same macro to the Word Developers
to illustrate the failings of the macro recorder: great idea but if it
cannot record one simple command, it is in need of an overhaul.)

All you need to do is use this in your macro:

Selection.PasteSpecial DataType:=wdPasteText
 
Back
Top