Export (0) Print
Expand All

PictureFormat.Replace Method

Office 2007
Replaces the specified picture. Returns Nothing.

Syntax

expression.Replace(Pathname, InsertAs)

expression   A variable that represents a PictureFormat object.

Parameters

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.

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.

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

pbPictureInsertAsEmbedded
pbPictureInsertAsLinked
pbPictureInsertAsOriginalState

Example

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

Visual Basic for Applications
Sub ReplaceLogo()

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


strExistingArtName = "C:\path\logo 1.bmp"
strReplaceArtName = "C:\path\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.

Visual Basic for Applications
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



Community Additions

ADD
Show:
© 2015 Microsoft