PPT2000: How to Change Image Links Programmatically (257221)



The information in this article applies to:

  • Microsoft PowerPoint 2000

This article was previously published under Q257221

SUMMARY

This article provides a sample Microsoft Visual Basic for Applications macro (Sub procedure) that prompts you to change the path to a linked picture object and change the linked source of this object to a location or image.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. NOTE: The following macro examples work only in PowerPoint. Visual Basic for Applications macros are not supported by the Microsoft PowerPoint Viewer. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

Sample Visual Basic Procedure

Sub ChangePictLink()

' Enable the error handling routine.
    On Error GoTo ErrorHandler
    
    Dim lChangeWhat As VbMsgBoxResult
    Dim strChangeWhat As String
    Dim strPictSource As String
    Dim strPictPath As String
    Dim strPictName As String
    Dim lConfirm As VbMsgBoxResult
    Dim strConfirm As String
    Dim lPictNamPos As Long
    
' This macro works with the selection object, so you 
' must be editing a slide.
    With ActiveWindow.Selection.ShapeRange.LinkFormat

' Set and get the full path for the picture.
        strPictSource = .SourceFullName
        
' If the selection object is not linked, raise an error.
        If strPictSource = "" Then
            GoTo ErrorHandler
        End If

' Find where the file name starts; then extract out the
' file name and the file path and store them in separate
' variables.
        lPictNamPos = InStrRev(strPictSource, "\", , vbTextCompare)
        strPictName = Right(strPictSource, _
          Len(.SourceFullName) - lPictNamPos)
        strPictPath = Left(strPictSource, lPictNamPos)
        
' Prompt the user as to what to change.
        lChangeWhat = MsgBox("Do you want to change the file name?", _
          vbYesNo, "Change What")
        
' If user wants to change the file name, then prompt 
' for the new name, and append it to the path.
        If lChangeWhat = vbYes Then
            strChangeWhat = InputBox("Type a new name for the picture", _ 
              "Change Name", strPictName)
            strConfirm = strPictPath & strChangeWhat
        Else

' Else, if the user wants to change the path, then prompt 
' for the new path to the file, and append the file name
' to the new path.
            strChangeWhat = InputBox("Type a new name for the path", _
              "Change Path", strPictPath)
            strConfirm = strChangeWhat & strPictName
        End If
        
' Confirm that the information is correct. If it is,
' set the link path to the new one and display a confirmation
' message.
        lConfirm = MsgBox("Is this correct?" & Chr(10) & strConfirm, _
          vbYesNo, "Name Check")
        If lConfirm = vbYes Then
            .SourceFullName = strConfirm
            MsgBox "The picture has been updated", vbOKOnly, "Link Updated"
        Else

' Else, don't make the change and prompt the user to try again.
            MsgBox "Please run this macro again.", vbOKOnly, "Wrong Name"
        End If
    End With
    Exit Sub
    
' If no selection or if the picture is not linked, display error message.
ErrorHandler:
    MsgBox "You must select a linked picture when using this macro.", _ 
      , "Error: No Picture Selected"
End Sub

				

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto kbProgramming KB257221