VBA - Paste charts to PPT

margaux

New Member
Joined
May 13, 2016
Messages
6
Hi All,

I am using the below code to paste charts to PPT to specific slides.

For each chart, I would like to be able to:
- set the chart size as I wish
- add a ppt text box below my chart where I can add comments.

Someone can help me? Cheers

HTML:
Sub copierppt()Dim PPT As PowerPoint.ApplicationDim PptDoc As PowerPoint.PresentationDim NbShpe As ByteDim i As Integer
Set PPT = CreateObject("Powerpoint.Application")PPT.Visible = True 'l'application sera visible
Set PptDoc = PPT.Presentations.Open("H:\Marketing Strategy\Attrition Report\Attrition Q1+Q2\Attrition\Attrition.pptx")

    '3 ###################  slide 3 ####################    PPT.ActiveWindow.View.GotoSlide Index:=3
    ThisWorkbook.Worksheets("OVERVIEW_SUMMARISE").ChartObjects("C_OS_1").Copy
    PPT.ActiveWindow.Panes(1).Activate
    PPT.CommandBars.ExecuteMso ("PasteSourceFormatting")    NbShpe = PptDoc.Slides(3).Shapes.Count
    With PptDoc.Slides(3).Shapes(NbShpe)        .Left = 50        .Top = 230        .Height = 300        .Width = 700    End With    DoEvents            '4 ###################  slide 4 ####################    PPT.ActiveWindow.View.GotoSlide Index:=4
    ThisWorkbook.Worksheets("OVERVIEW_SUMMARISE").ChartObjects("C_OS_2").Copy
    PPT.ActiveWindow.Panes(1).Activate
    PPT.CommandBars.ExecuteMso ("PasteSourceFormatting")    NbShpe = PptDoc.Slides(4).Shapes.Count
    With PptDoc.Slides(4).Shapes(NbShpe)        .Left = 50        .Top = 230        .Height = 300        .Width = 700    End With            'Clean up    Set PPSlide = Nothing    Set PPPres = Nothing    Set PPApp = Nothing    End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
See code below, easier to read like that

Code:
Sub copierppt()
Dim PPT As PowerPoint.Application
Dim PptDoc As PowerPoint.Presentation
Dim NbShpe As Byte
Dim i As Integer


Set PPT = CreateObject("Powerpoint.Application")
PPT.Visible = True 'l'application sera visible


Set PptDoc = PPT.Presentations.Open("H:\Marketing Strategy\Attrition Report\Attrition Q1+Q2\Attrition\Attrition.pptx")




    '3 ###################  slide 3 ####################
    PPT.ActiveWindow.View.GotoSlide Index:=3


    ThisWorkbook.Worksheets("OVERVIEW_SUMMARISE").ChartObjects("C_OS_1").Copy


    PPT.ActiveWindow.Panes(1).Activate


    PPT.CommandBars.ExecuteMso ("PasteSourceFormatting")
    NbShpe = PptDoc.Slides(3).Shapes.Count


    With PptDoc.Slides(3).Shapes(NbShpe)
        .Left = 50
        .Top = 230
        .Height = 300
        .Width = 700
    End With
    DoEvents
    
        '4 ###################  slide 4 ####################
    PPT.ActiveWindow.View.GotoSlide Index:=4


    ThisWorkbook.Worksheets("OVERVIEW_SUMMARISE").ChartObjects("C_OS_2").Copy


    PPT.ActiveWindow.Panes(1).Activate


    PPT.CommandBars.ExecuteMso ("PasteSourceFormatting")
    NbShpe = PptDoc.Slides(4).Shapes.Count


    With PptDoc.Slides(4).Shapes(NbShpe)
        .Left = 50
        .Top = 230
        .Height = 300
        .Width = 700
    End With
    
    
    'Clean up
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set PPApp = Nothing
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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