none
Replace all the images in powerpoint slides RRS feed

  • Question

  • Hi,

    I want to replace all the images, whether it is of msoPicture, or it is contained in the msogroup, or it is inserted as embededOleObject.

    I have code to replace msoPicture:

    if (shape.Type == Office.MsoShapeType.msoPicture)
    {

    //Code to replace image

    }

    But how to find and replace the pictures in msoGroup and the pictures inserted as "embededOleObject".

    Plz.. help..

    Thanks in advance..

    Tuesday, May 14, 2013 7:46 AM

All replies

  • Hi Gaurav,

    Thank you for posting in the MSDN Forum.

    You can take a look into Change a picture in VBA powerpoint.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 15, 2013 12:50 PM
    Moderator
  • Here is code that you might be able to review and get some ideas for your particular project. This routine I'm showing you will pull all of the pictures from a given PowerPoint slide and place them into an open Word document.

    As you will see, you have to look at the various shape types as well as PowerPoint placeholder containers to determine if you have picked up all images. The example is in VB.Net but I'm sure you can run it through a converter to see how it would read in "C".

    Hope this helps

        Private Sub InsertPictures(ByVal sld As PowerPoint.Slide)
            Dim shp As PowerPoint.Shape
            Dim str As String = Nothing
            Try
                rng.InsertParagraphBefore()
                rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
                With rng
                    .Text = "Pictures from Slide " & sld.SlideNumber.ToString & ":"
                    .Font.Underline = Word.WdUnderline.wdUnderlineSingle
                End With
                rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
    
                For Each shp In sld.Shapes
                    If shp.Type = Microsoft.Office.Core.MsoShapeType.msoPicture OrElse
                        shp.Type = Microsoft.Office.Core.MsoShapeType.msoLinkedPicture Then
                        shp.Copy()
                        rng.InsertParagraphBefore()
                        rng.MoveStart(Word.WdUnits.wdParagraph, Count:=1)
                        rng.Paste()
                        rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
                    ElseIf shp.Type = Office.MsoShapeType.msoPlaceholder Then
                        shp.Copy()
                        If shp.PlaceholderFormat.ContainedType = Microsoft.Office.Core.MsoShapeType.msoPicture OrElse
                             shp.PlaceholderFormat.ContainedType = Microsoft.Office.Core.MsoShapeType.msoLinkedPicture Then
                            If shp.HasTextFrame = Microsoft.Office.Core.MsoTriState.msoFalse Then
                                rng.InsertParagraphBefore()
                                rng.MoveStart(Word.WdUnits.wdParagraph, Count:=1)
                                rng.Paste()
                                rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
                            End If
                        End If
                    End If
                Next
                rng.InsertParagraphAfter()
                rng.MoveStart(Word.WdUnits.wdParagraph, Count:=1)
            Catch ex As Exception
                Err.Clear()
                rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
                rng.InsertParagraphAfter()
                rng.MoveStart(Word.WdUnits.wdParagraph, Count:=1)
            End Try
        End Sub
    


    Kind Regards, Rich ... http://greatcirclelearning.com

    Wednesday, May 15, 2013 4:21 PM
  • Thanks for your reply,

    But the issue is with the grouped images i.e. the images that are kept together as a group, so for that shape , shape type comes out to be

    "shape.Type = Microsoft.Office.Core.MsoShapeType.msoGroup"

    How to replace such images that are contained in a group.

    Tuesday, May 21, 2013 8:34 AM