• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to covert below code to Dynamic in VBA

Alenp

New Member
ActiveSheet.ChartObjects("Slide11_Chart1").Activate
ActiveChart.PlotArea.Select
ActiveChart.HasAxis(xlCategory) = True
ActiveChart.Axes(xlValue).MinimumScale = Sheets("Slide 11").Range("I21").Value
ActiveChart.Axes(xlValue).MaximumScale = Sheets("Slide 11").Range("I20").Value
ActiveChart.SetElement (msoElementPrimaryCategoryAxisNone)
ActiveChart.SetElement (msoElementPrimaryValueAxisNone)

ActiveSheet.ChartObjects("Slide11_Chart2").Activate
ActiveChart.PlotArea.Select
ActiveChart.HasAxis(xlCategory) = True
ActiveChart.Axes(xlValue).MinimumScale = Sheets("Slide 11").Range("B21").Value
ActiveChart.Axes(xlValue).MaximumScale = Sheets("Slide 11").Range("B20").Value
ActiveChart.SetElement (msoElementPrimaryCategoryAxisNone)
ActiveChart.SetElement (msoElementPrimaryValueAxisNone)


once after this i wanted to send the Graphs to PPT Directly, please can any one help me on this...
 
Here we go!

Code:
Sub ExportChartsToPowerPoint()
    Dim pptApp As Object
    Dim pptPres As Object
    Dim chartObj As ChartObject
    Dim slideIndex As Integer
    
    ' Create a new instance of PowerPoint application
    Set pptApp = CreateObject("PowerPoint.Application")
    pptApp.Visible = True ' Make PowerPoint visible
    
    ' Create a new presentation
    Set pptPres = pptApp.Presentations.Add
    
    slideIndex = 1 ' Initialize slide index
    
    ' Loop through each chart object in the worksheet
    For Each chartObj In Sheets("Slide 11").ChartObjects
        With chartObj.Chart
            ' Copy the chart
            .ChartArea.Copy
            
            ' Paste the chart into PowerPoint
            pptPres.Slides.Add slideIndex, 1 ' Add a new slide
            pptPres.Slides(slideIndex).Shapes.PasteSpecial
            
            ' Adjust the position and size of the pasted chart
            With pptPres.Slides(slideIndex).Shapes(1)
                .Left = 100 ' Adjust the left position as needed
                .Top = 100 ' Adjust the top position as needed
                .Width = 400 ' Adjust the width as needed
                .Height = 300 ' Adjust the height as needed
            End With
            
            slideIndex = slideIndex + 1 ' Increment slide index
        End With
    Next chartObj
    
    ' Clean up
    Set pptPres = Nothing
    Set pptApp = Nothing
End Sub
 
Thank you Monty for your valuable time and code. Can you please make it Dynamic as i have lot of Graphs in different sheets
 
Back
Top