Hey Leute,
habe ein kleines Problem mit dem unten stehenden VBA Code, welcher mich noch wahnsinnig macht. Bevor ich auf Windows 10 umgestiegen bin, hat alles noch einwandfrei geklappt. Immer wenn ich den Code ausfuehre, spuckt er mir folgenden Fehlercode aus.
Der Code soll vorliegende Excel-Diagramme in eine Powerpoint-Vorlage einfuegen bzw. die alten Diagramme in der PP mit denen aus der Excel zu ersetzen. Die Powerpointrefferenz in VBA ist gesetzt und sonst ist auf meinem Rechner alles up to date. Ich benutze Windows 10 und Excel sowie Powerpoint 2016.
Ich hoffe auf eure Hilfe :D
Der Code sieht wie folgt aus:
Private Sub Workbook_Open()
Dim sourceFileName As String
Dim oldFilePath1 As String
Dim newFilePath1 As String
Dim oldFilePath2 As String
Dim newFilePath2 As String
Dim testnumber As String
'The file name and path of the PowerPoint-file to update:
sourceFileName = ThisWorkbook.Sheets("Sheet1").Cells(1, 1).Value
'The new file path as a string (the text to replace with)
newFilePath1 = ThisWorkbook.Sheets("Sheet1").Cells(6, 1).Value
testnumber = ThisWorkbook.Sheets("Sheet1").Cells(8, 1).Value
If Len(newFilePath1) = 0 Then
Else
'Set the link to the Object Library:
'Tools -> References -> Microsoft PowerPoint x.xx Object Library
Select Case testnumber
Case 1
oldFilePath1 = "D:\Users\187\Documents\Templates\_1\01_Ausgewertet.xls"
Case 2
oldFilePath1 = "D:\Users\187\Documents\Templates\_2\01_Ausgewertet.xls"
Case 3
oldFilePath1 = "D:\Users\187\Documents\Templates\_3\01_Ausgewertet.xls"
Case 4
oldFilePath1 = "D:\Users\187\Documents\Templates\_4\01_Ausgewertet.xls"
Case 5
oldFilePath1 = "D:\Users\187\Documents\Templates\_5\01_Ausgewertet.xls"
End Select
Dim pptApp As PowerPoint.Application
Dim pptPresentation As Object
Dim pptSlide As Object
Dim pptShape As Object
Dim StartTime As Double
Dim SecondsElapsed As Double
'Remember time when macro starts
StartTime = Timer
'Set the variable to the PowerPoint Application
Set pptApp = New PowerPoint.Application
'Make the PowerPoint application visible
pptApp.Visible = True
'Set the variable to the PowerPoint Presentation
Set pptPresentation = pptApp.Presentations.Open(sourceFileName)
' Round 1 for first Excel File
'Loop through each slide in the presentation
For Each pptSlide In pptPresentation.Slides
'Loop through each shape in each slide
For Each pptShape In pptSlide.Shapes
'Find out if the shape is a linked object or a linked picture
If pptShape.Type = msoLinkedPicture Or pptShape.Type _ = msoLinkedOLEObject Then
'Use Replace to change the oldFilePath to the newFilePath
pptShape.LinkFormat.SourceFullName = Replace(LCase _ (pptShape.LinkFormat.SourceFullName),
LCase(oldFilePath1), newFilePath1)
End If
Next
Next
pptPresentation.UpdateLinks
'Save, close and quit the application
pptPresentation.Save
pptPresentation.Close
pptApp.Quit
'Release the memory
Set pptApp = Nothing
Set pptPresentation = Nothing
Set pptSlide = Nothing
Set pptShape = Nothing
'Determine how many seconds code took to run
SecondsElapsed = Round(Timer - StartTime, 2)
' Clear Excel file to prevent from accidental start when opened later: ThisWorkbook.Sheets("Sheet1").Range("A1:A7").ClearContents
End If
End Sub
|