I need to copy chart1 and chart2 from excel to powerpoint.
I have multiple sheets and I am doing this:
I am getting the remote server machine does not exist or is unavailable
I am comparing the sheet name to a string, so that I can copy Chart1 from all the sheets, with a specific name.
Any help will be greatly appreciated.
Thanks.
I have multiple sheets and I am doing this:
VBA Code:
Sub ppt()
Dim r As Range
Dim app As PowerPoint.Application
Dim currentSlide As PowerPoint.slide
Dim Xchart As Excel.ChartObject
Dim WS_Count As Integer
On Error Resume Next
Set app = GetObject(, "PowerPoint.Application")
On Error GoTo 0
'Open PowerPoint if not active
If app Is Nothing Then
Set app = New PowerPoint.Application
End If
'Create new presentation in PowerPoint
If app.Presentations.Count = 0 Then
app.Presentations.Add
End If
'Display the PowerPoint presentation
app.Visible = True
Dim i As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
Application.ScreenUpdating = False
'Assign range to variable r
'if powerpoint is closed
If app Is Nothing Then Set app = CreateObject(class:="PowerPoint.Application")
'if powerpoint is open
Set app = GetObject(class:="PowerPoint.Application")
Set presentation = app.Presentations.Add
For i = 1 To WS_Count
'MsgBox ActiveWorkbook.Worksheets(i).Name
If ActiveWorkbook.Worksheets(i).Name ="Graphs" then
'I am getting the remote server machine does not exist or is unavailable in the next line
app.ActivePresentation.Slides.Add app.ActivePresentation.Slides.Count + 1, ppLayoutText
app.ActiveWindow.View.GotoSlide app.ActivePresentation.Slides.Count
Set currentSlide = app.ActivePresentation.Slides(app.ActivePresentation.Slides.Count)
Chart1.Copy
currentSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
EndIf
I am getting the remote server machine does not exist or is unavailable
I am comparing the sheet name to a string, so that I can copy Chart1 from all the sheets, with a specific name.
Any help will be greatly appreciated.
Thanks.