Table of contents
Collapse the table of content
Expand the table of content

PictureFormat.ReplaceEx Method (Publisher)

office 365 dev account|Last Updated: 8/24/2017
3 Contributors

Replaces the specified picture, optionally fitting the replacement picture to the frame or filling the frame. Returns nothing.


expression. ReplaceEx( Pathname, InsertAs, Fit)

_expression_A variable that represents a PictureFormat object.


NameRequired/OptionalData TypeDescription
PathnameRequiredStringThe name and path of the file with which you want to replace the specified picture.
InsertAsOptionalPbPictureInsertAsThe manner in which you want the picture file inserted into the document: linked or embedded.
FitOptionalpbPictureInsertFitWhether the inserted picture is fit to the frame, or fills the frame.


The InsertAs parameter can be one of the following PbPictureInsertAs constants declared in the Microsoft Publisher type library. The default value is pbPictureInsertAsOriginalState.

| pbPictureInsertAsEmbedded| | pbPictureInsertAsLinked| | pbPictureInsertAsOriginalState|


The following Microsoft Visual Basic for Applications (VBA) macro shows how to use the ReplaceEx method to replace all the pictures in a publication with a different picture. In this example, the replacement picture is fit to the frames of the previous pictures, but you can use pbFill in place of pbFit if you want to fill the frames instead. This example also excludes pictures on master pages.

Before running this macro, replace replacementPicturePath with the path to the picture you want to use as the replacement.

Public Sub ReplaceEx_Example()

    Dim pubPage As Page
    Dim pubShape As Shape
    Dim strReplacePicturePath As String

    strReplacePicturePath = replacementPicturePath

    For Each pubPage In ActiveDocument.Pages

        For Each pubShape In pubPage.Shapes

            If pubShape.Type = pbPicture Then

                pubShape.PictureFormat.ReplaceEx strReplacePicturePath, pbPictureInsertAsOriginalState, pbFit

            End If

        Next pubShape

    Next pubPage

End Sub
© 2018 Microsoft