Green_Square_Window
New Member
- Joined
- Feb 6, 2024
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
The macro below opens an existing powerpoint presentation, finds the appropriate slide, duplicates it and moves it to the end of the deck, then pastes across a chart from Excel to the slide. It does this for various slides and charts using for loops. When I step through the code it works fine, but it breaks when I run it on this line: Set sld = PowerPointPresentation.Slides(PowerPointPresentation.Slides.Count)
The error message is: "The remote server machine doe not exist or is unavailable." The run-time error is 462. Any help with this would be much appreciated - I am new to manipulating PowerPoint with VBA.
Thanks very much
The error message is: "The remote server machine doe not exist or is unavailable." The run-time error is 462. Any help with this would be much appreciated - I am new to manipulating PowerPoint with VBA.
Thanks very much
VBA Code:
Sub Duplicate_Slide()
Dim PowerPointApp As Object
Dim PowerPointPresentation As Object
Dim PresentationPath As String
' Set the path to the PowerPoint presentation
PresentationPath = "C:\Users\XXXX\Desktop\XXXX.pptx"
' Create a new instance of PowerPoint application
Set PowerPointApp = CreateObject("PowerPoint.Application")
' Open the PowerPoint presentation
Set PowerPointPresentation = PowerPointApp.Presentations.Open(PresentationPath)
Dim i As Integer
Dim j As Integer
For i = 1 To ThisWorkbook.Sheets("Create_Slides").Range("Strategies_2D").rows.Count
Dim max As Integer
max = ThisWorkbook.Sheets("Create_Slides").Range("Count").rows(i).Value
Dim chartRef As String
chartRef = ThisWorkbook.Sheets("Create_Slides").Range("Charts").rows(i).Value
Dim slideIndex As Integer
slideIndex = ThisWorkbook.Sheets("Create_Slides").Range("Slide").rows(i).Value
For j = 1 To max
Dim slideToDuplicate As PowerPoint.Slide
Set slideToDuplicate = PowerPointPresentation.Slides(slideIndex)
slideToDuplicate.Copy
PowerPointPresentation.Slides.Paste PowerPointPresentation.Slides.Count + 1
Dim sld As PowerPoint.Slide
Dim ExcelChart As chartObject
Dim sheetRef As String
Dim strat As Integer
strat = ThisWorkbook.Sheets("Create_Slides").Range("Strategies_2D").Cells(i, j).Value
sheetRef = "Strategy_" & strat
Set ExcelChart = ThisWorkbook.Sheets(sheetRef).ChartObjects(chartRef)
ExcelChart.chart.ChartArea.Copy
Set sld = PowerPointPresentation.Slides(PowerPointPresentation.Slides.Count)
sld.Shapes.Paste
Set sld = Nothing
Set ExcelChart = Nothing
Set slideToDuplicate = Nothing
Next j
Next i
PowerPointApp.Visible = True
End Sub
Last edited by a moderator: