Paste Special in VBA

G

Guest

I want to paste through VBA code in PPT, but I want it to do Paste Special > Unformatted Text. Is there a way to do this in VBA code?
 
B

Brian Reilly, MS MVP

Here's the text from the Help file in PPT 2003 on Using PasteSpecial
in VBA. It was added in PPT 2002, I believe and was not available
prior to that point.

Brian Reilly, PowerPoint MVP

PasteSpecial Method
See AlsoApplies ToExampleSpecificsPastes the contents of the Clipboard
using a special format. Although the syntax for using this method is
the same for all objects in the Applies To list, the behavior is
slightly different, depending on the object calling the PasteSpecial
method.

Object Behavior
Shapes Adds the shape to the collection of shapes in the specified
format. If the specified data type is a text data type, then a new
text box is created with the text. If the paste succeeds, the
PasteSpecial method returns a ShapeRange object representing the shape
range that was pasted.
TextRange Replaces the text range with the contents of the Clipboard
in the format specified. Valid data types for this object are
ppPasteText, ppPasteHTML, and ppPasteRTF (any other format generates
an error). If the paste succeeds, this method returns a TextRange
object representing the text range that was pasted.
View Pastes the current contents of the Clipboard into the view
represented by the View object. Valid views for the PasteSpecial
method are the same as those for the Paste method. If the data type
can’t be pasted into the view (for example, trying to paste a picture
into Slide Sorter View), then an error occurs.


expression.PasteSpecial(DataType, DisplayAsIcon, IconFileName,
IconIndex, IconLabel, Link)


expression Required. An expression that returns one of the above
objects.

DataType Optional PpPasteDataType . A format for the Clipboard
contents when they're inserted into the document. The default value
varies, depending on the contents in the Clipboard. An error occurs if
the specified data type in the DataType argument is not supported by
the clipboard contents.

PpPasteDataType can be one of these PpPasteDataType constants.
ppPasteBitmap
ppPasteDefault default
ppPasteEnhancedMetafile
ppPasteGIF
ppPasteHTML
ppPasteJPG
ppPasteMetafilePicture
ppPasteOLEObject
ppPastePNG
ppPasteRTF
ppPasteShape
ppPasteText

DisplayAsIcon Optional MsoTriState . MsoTrue to display the embedded
object (or link) as an icon.

MsoTriState can be one of these MsoTriState constants.
msoCTrue Does not apply to this method.
msoFalse default Does not display the embedded object (or link) as an
icon.
msoTriStateMixed Does not apply to this method.
msoTriStateToggle Does not apply to this method.
msoTrue Displays the embedded object (or link) as an icon.

IconFileName Optional String. If DisplayAsIcon is set to msoTrue,
this argument is the path and file name for the file in which the icon
to be displayed is stored. If DisplayAsIcon is set to msoFalse, this
argument is ignored.

IconIndex Optional Long. If DisplayAsIcon is set to msoTrue, this
argument is a number that corresponds to the icon you want to use in
the program file specified by IconFilename . Icons appear in the
Change Icon dialog box, accessed from the Standard toolbar (Insert
menu, Object command, Create New option): 0 (zero) corresponds to the
first icon, 1 corresponds to the second icon, and so on. If this
argument is omitted, the first (default) icon is used. If
DisplayAsIcon is set to msoFalse, then this argument is ignored. If
IconIndex is outside the valid range, then the default icon (index
0) is used.

IconLabel Optional String. If DisplayAsIcon is set to msoTrue,
this argument is the text that appears below the icon. If this label
is missing, Microsoft PowerPoint generates an icon label based on the
Clipboard contents. If DisplayAsIcon is set to msoFalse, then this
argument is ignored.

Link Optional MsoTriState . Determines whether to create a link to
the source file of the Clipboard contents. An error occurs if the
Clipboard contents do not support a link.

MsoTriState can be one of these MsoTriState constants.
msoCTrue Does not apply to this method.
msoFalse default Does not create a link to the source file of the
Clipboard contents.
msoTriStateMixed Does not apply to this method.
msoTriStateToggle Does not apply to this method.
msoTrue Creates a link to the source file of the Clipboard contents.

Remarks
An error occurs if there is no data on the Clipboard when the
PasteSpecial method is called.

Example
The following example pastes a bitmap image as an icon into another
window. This example assumes there are two open windows, and a bitmap
image in the first window is currently selected.

Sub PasteOLEObject()
Windows(1).Selection.Copy
Windows(2).View.PasteSpecial DataType:=ppPasteOLEObject, _
DisplayAsIcon:=msoTrue, IconLabel:="New Bitmap Image"
End Sub
 

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