Selection.PasteAndFormat method

  • Follow


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.
0
Reply Rick 2/11/2010 8:07:26 PM

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"Rick" <rick0726@verizon.net> wrote in message 
news:05bbd7d5-2efb-49ba-8bb8-23c5bbeefee6@c28g2000vbc.googlegroups.com...
> 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. 


0
Reply Graham 2/12/2010 7:35:29 AM


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?

On Feb 12, 2:35=A0am, "Graham Mayor" <gma...@REMOVETHISmvps.org> wrote:
> The macro recorder has never been a perfect tool. However in this instanc=
e -
> Edit > PasteSpecial unformatted text records as
>
> Selection.PasteSpecial Link:=3DFalse, DataType:=3DwdPasteText, Placement:=
=3D _
> =A0 =A0 =A0 =A0 wdInLine, DisplayAsIcon:=3DFalse
>
> Unformatted UnicodeText records as
>
> Selection.PasteSpecial Link:=3DFalse, DataType:=3D20, Placement:=3DwdInLi=
ne, _
> =A0 =A0 =A0 =A0 DisplayAsIcon:=3DFalse
>
> 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 wou=
ld
> be highlighted if you select the edit > paste special dialog). This varie=
s
> 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()
> =A0 =A0 On Error GoTo oops
> =A0 =A0 Selection.PasteSpecial _
> =A0 =A0 DataType:=3DwdPasteText, _
> =A0 =A0 Placement:=3DwdInLine
> =A0 =A0 End
> oops:
> Beep
> End Sub
>
> or with Word 2007, you can set the default paste options to your preferen=
ces
> in Word Options
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - =A0Word MVP
>
> My web sitewww.gmayor.com
> Word MVP web sitehttp://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
> "Rick" <rick0...@verizon.net> wrote in message
>
> news:05bbd7d5-2efb-49ba-8bb8-23c5bbeefee6@c28g2000vbc.googlegroups.com...
>
>
>
> > 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. =A0But th=
e
> > 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". =A0Thanks
> > for any thoughts about this.- Hide quoted text -
>
> - Show quoted text -

0
Reply Rick 2/12/2010 7:32:28 PM

2 Replies
5825 Views

(page loaded in 0.074 seconds)


Reply: