How to copy a graph from Excel to PowerPoint

Nando1988

New Member
Joined
Aug 21, 2019
Messages
23
I need to copy chart1 and chart2 from excel to powerpoint.
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.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I tried this code, and I get the following error:
VBA Code:
The item with the specified name wasn't found.

This is the code that I used:
Code:
Sheet2.ChartObjects("Chart1").Chart.ChartArea.Copy

Please help me fix this error.
Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top