Hallo ich habe folgendes Problem.
Ich möchte den Linknamen eines aus Excel verlinkten Diagramms in Powerpoint ändern.
Der Linkname heißt anfangs file:///(pfad), es gilt also
oshp.LinkFormat.SourceFullName == file:///(pfad)
Nun möchte ich den Namen ändern aber sobalt ich versuche oshp.LinkFormat.SourceFullName einen string zuzueisen, der mit file:/// beginnt bekomme ich einen Fehler. Genau genommen liegt es eignetlich nur an den /, wenn ich diese wegmache bleibt der Fehler aus. Folgendes funktioniert also nicht
oshp.LinkFormat.SourceFullName = file:///(anderer_pfad)
Hat jemand Lösungsvorschäge oder kennt den Grund? Hier das Programm.
Sub Update_Links()
'
' Updates the file path to the xls file in the same directory in case there is no connection to the server or the file is sent to the client
' Updates all links as well
'
If MsgBox("Are you sure you want to update?" & vbCrLf & "(Duration: approx. 10 minutes)", vbYesNo, "Save file") <> vbYes Then Exit Sub
Dim startTime As Double
startTime = Timer
Dim osld As Slide
Dim oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = msoLinkedOLEObject Then
If oshp.OLEFormat.ProgID Like "Excel*" Then
Dim splitString() As String
splitString = Split(oshp.LinkFormat.SourceFullName, "!")
Dim newPath As String
newPath = Replace(ActivePresentation.FullName, ".pptm", ".xlsx")
If Dir(newPath) <> "" Then
If Not FileLocked(newPath) Then
If oshp.LinkFormat.SourceFullName <> Replace(ActivePresentation.FullName, ".pptm", ".xlsx!" & splitString(1) & "!" & splitString(2)) Then
oshp.LinkFormat.SourceFullName = "file:///" & Replace(ActivePresentation.FullName, ".pptm", ".xlsx") & "!" & splitString(1) & "!" & splitString(2)
oshp.LinkFormat.Update
Else
MsgBox "Links are already updated"
Exit Sub
End If
Else
MsgBox "Excel file is still open. Please close it and try again!"
Exit Sub
End If
Else
MsgBox "File" & vbCrLf & "'" & newPath & "'" & vbCrLf & "does not exists. Cancelling link update."
Exit Sub
End If
End If
End If
Next oshp
Next osld
Dim duration As Double
Dim minutes As Integer
duration = Round(Timer - startTime, 2)
minutes = Round(duration / 60, 0)
seconds = duration Mod (60)
MsgBox "Update successful!" & vbCrLf & "Duration: " & minutes & " minutes & " & seconds & " seconds"
End Sub
Dankeschön
|