VBA Power Point (Vinculo)

salvador

15-07-2015 15:11:53

Amigos, boa tarde!

Encontrei uma solução importantíssima para mim na net, mas não está funcionando.
Tenho um arquivo no Excel vinculado no power point, porém todos os meses eu altero a pasta desse arquivo, consequentemente para eu poder atualizar meus gráficos que estão vinculados ao Excel eu tenho que ficar alterando a origem de vinculo por vinculo (Tenho mais de 80 vínculos). Procurando uma solução na net, encontrei o código abaixo, que deve ser colado num módulo do Power Point, executado, procurado o arquivo novo e automaticamente o caminho do arquivo se modifica. Considerando que as planilhas e os gráficos sempre serão os mesmos. Mas não está funcionando. No msgbox até aparece o novo link, mas quando eu visualizo em Links no PP não aparece a alteração! E o pior que em vários fóruns as pessoas dizem que funcionou perfeitamente!


Será que alguém ajudaria encontrar a solução


Vide código;

Código: Selecionar todos

Sub M1()
    Dim sld As Slide
    Dim sh As Shape
    Dim ExcelFileNew
    Dim exl As Object
    Set exl = CreateObject("Excel.Application")
     
     'Open a dialog box to promt for the new source file.
    ExcelFileNew = exl.Application.GetOpenFilename(, , "Select Excel File")
    Call stripPath(ExcelFileNew, filenameNew)
     
    For Each sld In ActivePresentation.Slides
        For Each sh In sld.Shapes
            If sh.Type = msoLinkedOLEObject Then
                With sh.LinkFormat
                    LinkOld = .SourceFullName
                    Call stripReference(LinkOld, fullpathOld)
                    Call stripPath(fullpathOld, filenameOld)
                    LinkNew = Replace(LinkOld, filenameOld, filenameNew)
                    .SourceFullName = LinkNew
                     'Call showStrings(ExcelFileNew, filenameNew, LinkOld, fullpathOld, filenameOld, LinkNew)
                End With
            End If
        Next sh
    Next sld
End Sub
 '
Sub stripPath(fullPath, filename)
     
     'This will take c:\folder\workbook.xlsx* and provide workbook.xlsx*
    Dim filenamePosition As Long
     
    filenamePosition = InStrRev(fullPath, "\")
    filename = Mid(fullPath, filenamePosition + 1, Len(fullPath) - filenamePosition)
     
End Sub
 '
Sub stripReference(fullReference, filename)
     
     'This will take *workbook.xls!Graphs![workbook.xls]Graphs Chart 1 and provide *workbook.xls
    Dim referencePosition As Long
     
    referencePosition = InStr(1, fullReference, "!")
    filename = Left(fullReference, referencePosition - 1)
     
End Sub
 '
Sub showStrings(ExcelFileNew, filenameNew, LinkOld, fullpathOld, filenameOld, LinkNew)
     
     'This is just a debugging function to display the variables
    MsgBox ("ExcelFileNew: " & ExcelFileNew & vbNewLine _
    & "filenameNew: " & filenameNew & vbNewLine _
    & "LinkOld: " & LinkOld & vbNewLine _
    & "fullpathOld: " & fullpathOld & vbNewLine _
    & "filenameOld: " & filenameOld & vbNewLine _
    & "LinkNew: " & LinkNew)
     
End Sub