none
How to copy a shape from powerpoint slide to MS word document? RRS feed

  • Question

  • I am not ablle to copy shape(s) from PPT to word in its orginal format. How can we achive this?

    The code i used which copies shapes in picture format:

    foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes) 
    { 
       
    if (targetDoc != null) 
       
    { 
          shape
    .Copy(); 
         
    this.wordApp.ActiveWindow.Selection.Paste(); 
       
    } 
     
    } 

    Wednesday, April 27, 2011 6:15 AM

Answers

  • Hi Parsad,

     

    Here is code I use to extract text from PowerPoint slide shapes. You should be able to adapt it to look for certain shape types.

     

        Private Sub ExtractSlideText()

            Dim item As Microsoft.Office.Interop.PowerPoint.Shape

            Dim textRange As String

            For Each item In slide.Shapes

                If item.HasTextFrame = Microsoft.Office.Core.MsoTriState.msoTrue Then

                    If item.TextFrame.HasText = Microsoft.Office.Core.MsoTriState.msoTrue Then

                        textRange = item.TextFrame.TextRange.Text

                        wdoc.Selection.TypeText(textRange)

                        wdoc.Selection.TypeParagraph()

                    End If

                End If

            Next

        End Sub

     

    Hope this helps


    Regards, Rich
    Wednesday, April 27, 2011 12:14 PM

All replies

  • Hi pasad,

    In Word's vba, you can paste a whole PowerPoint slide via:
    Selection.PasteSpecial DataType:=wdPasteOLEObject
    or:
    .PasteSpecial DataType:=0

    From Word's vba Help file:

    WdPasteDataType Enumeration

    Specifies the format for the Clipboard contents when they are inserted into a document.

    Name Value Description
    wdPasteBitmap 4 Bitmap.
    wdPasteDeviceIndependentBitmap 5 Device-independent bitmap.
    wdPasteEnhancedMetafile 9 Enhanced metafile.
    wdPasteHTML 10 HTML.
    wdPasteHyperlink 7 Hyperlink.
    wdPasteMetafilePicture 3 Metafile picture.
    wdPasteOLEObject 0 OLE object.
    wdPasteRTF 1 Rich Text Format (RTF).
    wdPasteShape 8 Shape.
    wdPasteText 2 Text.

    If you don't want to paste a whole slide and only want to paste a shape from the slide, you'll need to get the shape's type when you copy it, then use the same type for pasting. I'm not sure there's a 1:1 correspondence, though.

     


    Cheers
    Paul Edstein
    [MS MVP - Word]

     


    Wednesday, April 27, 2011 6:55 AM
  • Thanks Paul.

    Whenever I use  DataType:=wdPasteOLEObject , an exception will occur like "The specified data type is unavailable". 

    Code:

    shape.Copy();

    ...

    ...

     

    object objOLEO = WdPasteDataType.wdPasteOLEObject;
     

    wordApp.ActiveWindow.Selection.Range.PasteSpecial(

    ref objectMissing, ref objLink, ref objectMissing, ref objectMissing, ref objOLEO, ref objectMissing, ref objectMissing);

     


     

    Wednesday, April 27, 2011 10:33 AM
  • Hi Prasad,

    As per my previous post, the wdPasteOLEObject option will only work if you're copying and pasting the whole slide. Your original post suggests you might only be copying some of the slide's shapes.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Wednesday, April 27, 2011 10:38 AM
  • So there is no way to copy shapes from presentation slides to word doc?  I am searching for the sample's and could not  find any helpful resources. :(

    Thanks Paul for your time on this Qstn.


    Wednesday, April 27, 2011 11:06 AM
  • Hi pasad,

    As I said in my first post, where I gave you the table of paste formats:
    "If you don't want to paste a whole slide and only want to paste a shape from the slide, you'll need to get the shape's type when you copy it, then use the same type for pasting."
    If you do that, you can ensure that the pasted object's format is the same as that of the source object.


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Wednesday, April 27, 2011 11:50 AM
  • Try the C# equivalent of

    Selection.PasteSpecial DataType:=23

    (In VBA, it's not easy to find out which DataType to use, because not all the numbers are documented and they do not necessarily correspond to the numbers returned by the WIn32 API function EnumClipboardFormats. Perhaps there's an easier way to do it via .NET, but I got "23" using Word's VBA Macro recorder to record a Paste Special using the "Microsoft Office Graphic Object" in Office 2007/2010. For other types of shape you may need something else, as macropod says.



    Peter Jamieson
    Wednesday, April 27, 2011 12:08 PM
  • Hi Parsad,

     

    Here is code I use to extract text from PowerPoint slide shapes. You should be able to adapt it to look for certain shape types.

     

        Private Sub ExtractSlideText()

            Dim item As Microsoft.Office.Interop.PowerPoint.Shape

            Dim textRange As String

            For Each item In slide.Shapes

                If item.HasTextFrame = Microsoft.Office.Core.MsoTriState.msoTrue Then

                    If item.TextFrame.HasText = Microsoft.Office.Core.MsoTriState.msoTrue Then

                        textRange = item.TextFrame.TextRange.Text

                        wdoc.Selection.TypeText(textRange)

                        wdoc.Selection.TypeParagraph()

                    End If

                End If

            Next

        End Sub

     

    Hope this helps


    Regards, Rich
    Wednesday, April 27, 2011 12:14 PM