Share via


Replace Method [Publisher 2003 VBA Language Reference]

Replaces the specified picture. Returns Nothing.

expression.Replace(Pathname, [InsertAs])

expression Required. An expression that returns a PictureFormat object.

FileName   Required String. The name 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.

PbPictureInsertAs can be one of these PbPictureInsertAs constants.
pbPictureInsertAsEmbedded
pbPictureInsertAsLinked
pbPictureInsertAsOriginalStatedefault

Remarks

Use the Replace method to update linked picture files that have been modified since they were inserted into the document. Use the LinkedFileStatus property of the PictureFormat object to determine if a linked picture has been modified.

Example

The following example replaces every occurrence of a specific picture in the active publication with another picture.

Sub ReplaceLogo()

Dim pgLoop As Page
Dim shpLoop As Shape
Dim strExistingArtName As String
Dim strReplaceArtName As String


strExistingArtName = "C:\pathname\folder\logo 1.bmp"
strReplaceArtName = "C:\pathname\folder\logo 2.bmp"

For Each pgLoop In ActiveDocument.Pages
    For Each shpLoop In pgLoop.Shapes
        If shpLoop.Type = pbLinkedPicture Then
        
            With shpLoop.PictureFormat
                If .Filename = strExistingArtName Then
                    .Replace (strReplaceArtName)
                End If
            End With
            
        End If
    
    Next shpLoop
Next pgLoop
         
End Sub

This example tests each linked picture to determine if the linked file has been modified since it was inserted into the publication. If it has, the picture is updated by replacing the file with itself.

Sub UpdateModifiedLinkedPictures()

Dim pgLoop As Page
Dim shpLoop As Shape
Dim strPictureName As String


For Each pgLoop In ActiveDocument.Pages
    For Each shpLoop In pgLoop.Shapes
        If shpLoop.Type = pbLinkedPicture Then
        
            With shpLoop.PictureFormat
                If .LinkedFileStatus = pbLinkedFileModified Then
                    strPictureName = .Filename
                    .Replace (strPictureName)
                End If
            End With
            
        End If
    Next shpLoop
Next pgLoop

End Sub

Applies to | PictureFormat Object