Article ID: 164939
Article Last Modified on 10/11/2006
Microsoft PowerPoint 8.0 Object Library
Microsoft Word 8.0 Object Library
Sub PowerPointPasteSpecial()
On Error Resume Next
Err.Clear
Dim MyDoc As Word.Document
Dim lSlideNum As Long
'Copies the current selection in PowerPoint to the clipboard.
'If nothing is selected a run-time error will occur.
PowerPoint.ActiveWindow.Selection.Copy
If Err.Number <> 0 Then
MsgBox "Nothing is selected or not in a valid view.", _
vbExclamation, "Invalid Selection"
End
End If
'Get the current slide number.
lSlideNum = ActiveWindow.Selection.SlideRange.SlideNumber
'Creates a new document in Word.
Set MyDoc = Word.Documents.Add()
If Err.Number <> 0 Then
MsgBox "Word is not running or available. Start Word and " _
& "run the macro again.", vbExclamation, "Word Not Running"
End
End If
'Pastes the information on the Clipboard into the Word document as
'an Enhanced Metafile. If the information on the Clipboard is text
'you receive a run-time error. Text does not support pasting as
'a metafile.
Word.ActiveWindow.Selection.PasteSpecial _
DataType:=wdPasteEnhancedMetafile
If Err.Number <> 0 Then
MsgBox "Object information not on the Clipboard. Select an object " _
& "in PowerPoint and run the macro again." & Chr(13) & Chr(13) _
& "Having text information in the clipboard would cause this" _
& " problem.", vbExclamation, "Incorrect Data In Clipboard"
End
End If
'Copies the object, which is now an enhanced metafile to Clipboard.
Word.ActiveWindow.Selection.Copy
'Pastes the metafile onto the PowerPoint slide.
PowerPoint.ActivePresentation.Slides(lSlideNum).Shapes.Paste
'Close the document without saving changes.
MyDoc.Close (wdDoNotSaveChanges)
End Sub
176476 OFF: Office Assistant Not Answering Visual Basic Questions
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 97 8.00 kbmacro kbpptvba ppt8 vba vbe
Keywords: kbcode kbdtacode kbhowto kbmacro kbprogramming KB164939