PictureFormat.ReplaceEx method (Publisher)

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

Syntax

expression.ReplaceEx (PathName, InsertAs, Fit)

expression A variable that represents a PictureFormat object.

Parameters

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. Can be one of the PbPictureInsertAs constants declared in the Microsoft Publisher type library; the default value is pbPictureInsertAsOriginalState.
Fit Optional PbPictureInsertFit Whether the inserted picture is fit to the frame or fills the frame.

Example

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 that 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

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.