PictureFormat.ReplaceEx Method (Publisher)

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.


Name Required/Optional Data Type Description
Pathname Required String The name and path of the file with which you want to replace the specified picture.
InsertAs Optional PbPictureInsertAs The manner in which you want the picture file inserted into the document: linked or embedded.
Fit Optional pbPictureInsertFit Whether 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.



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