Selection.PasteAndFormat method

R

Rick

In Word 2007, when I record a macro that does a regular Paste from the
clipboard, it records it as

Selection.PasteAndFormat(wdPasteDefault)

It also seems to use the same 'wdPasteDefault' type even if I choose
either--

Paste Special | Unformatted Text; or
Paste Special | Unformatted Unicode Text

I'm not sure why it would use the same type for all of these. But the
strange thing is that if I go to the Word Developer Help for the
PasteAndFormat method, and I see what values there are for the
wdRecoveryType, it lists wdPasteDefault as "Not Supported". Thanks
for any thoughts about this.
 
G

Graham Mayor

The macro recorder has never been a perfect tool. However in this instance -
Edit > PasteSpecial unformatted text records as

Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False

Unformatted UnicodeText records as

Selection.PasteSpecial Link:=False, DataType:=20, Placement:=wdInLine, _
DisplayAsIcon:=False

Data type 20 is wdFormatSurroundingFormattingWithEmphasis

and a simple paste records as

Selection.Paste

in Word 2007 all of which are correct.

Selection.PasteAndFormat (wdPasteDefault)

Uses the default format for the material on the clipboard (that which would
be highlighted if you select the edit > paste special dialog). This varies
with the type of material in question, so does not represent a fixed
definition.

To force a particular type create the macro manually e.g.

Sub PasteUnfText()
On Error GoTo oops
Selection.PasteSpecial _
DataType:=wdPasteText, _
Placement:=wdInLine
End
oops:
Beep
End Sub

or with Word 2007, you can set the default paste options to your preferences
in Word Options

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Rick

Thanks. In Word 2007, on the clipboard I have a string of text I just
copied from my Word document. When I then record a macro and do any
of these --

- regular Paste
- Paste Special | Unformatted text
- Paste Special | Unformatted Unicode text

the code that I get in the VBA Editor is just --

Selection.PasteAndFormat (wdPasteDefault)

I wonder why I'm getting a different result than you?
 

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