Home » excel » excel – Spinning 3D chart in PowerPoint presentation

excel – Spinning 3D chart in PowerPoint presentation

Posted by: admin March 9, 2020 Leave a comment

Questions:

I created a macro in Excel that will spin a 3D chart. I copied the chart into PowerPoint, set up the code to run in PowerPoint when the slide is shown. The code runs, but I cannot get it to actually change what is shown on the screen. When the slide is in edit mode, the graph rotates. Any idea how to get the code to not just run (I can see the debug numbers showing up), but update the screen when in Presentation Mode? My code is:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub SpinTheChart()

    RotateX = ActivePresentation.Slides(2).Shapes(2).Chart.ChartArea.Format _
                    .ThreeD.RotationX

    Do While ActivePresentation.SlideShowWindow.View.CurrentShowPosition = 2
        RotateX = RotateX + 7
        If RotateX > 360 Then RotateX = RotateX - 360
        ActivePresentation.Slides(2).Shapes(2).Chart.ChartArea.Format _
                    .ThreeD.RotationX = RotateX
        DoEvents
        Sleep 125
        Debug.Print RotateX
    Loop

End Sub

Sub OnSlideShowPageChange()
    Dim i As Integer
    i = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
    If i = 2 Then SpinTheChart
End Sub

UPDATE:
I am still fighting this. It seems some recomendations say to update the currently displayed chart, you need to use, below the DoEvents:

SlideShowWindows(1).View.GotoSlide SlideSowWindows(1).View.CurrentShowPosition

but this does not work. It exits any code that is running. So the Do/Loop in the first function is exited and it does not go on to the second iteration.

How to&Answers:

If the chart spins in Edit mode, why don’t you record it as a .GIF an include that in the presentation?

Add an animated GIF to PowerPoint: https://support.office.com/en-us/article/Add-an-animated-GIF-to-a-slide-3a04f755-25a9-42c4-8cc1-1da4148aef01

Recording your screen: http://www.screentogif.com

Answer:

It seems wether changes on charts not trigger the SlideShowView refresh. But changes on text in shapes will do this. So the following code spins the chart:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Sub SpinTheChart()

 Set oSlide = ActivePresentation.Slides("Slide1")
 Set oChart = oSlide.Shapes("Diagramm 4").Chart
 oChart.ChartArea.Format.ThreeD.RotationX = 20

 snRotationX = oChart.ChartArea.Format.ThreeD.RotationX

 Do While ActivePresentation.SlideShowWindow.View.Slide.Name = "Slide1"

  snRotationX = snRotationX + 7
  If snRotationX > 360 Then snRotationX = snRotationX - 360
  oChart.ChartArea.Format.ThreeD.RotationX = snRotationX

  'oSlide.Shapes("Rechteck 7").TextFrame.TextRange.Text = snRotationX
  oSlide.Shapes.Title.TextFrame.TextRange.Text = oSlide.Shapes.Title.TextFrame.TextRange.Text

  DoEvents
  Sleep 125

 Loop
End Sub

Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
 If SSW.View.Slide.Name = "Slide1" _
  Then SpinTheChart
End Sub

You are familiar with the other issues with macros during a powerpoint presentation? They are very fragile in such environment and their effects have to be tested carefully.

And OnSlideShowPageChange works only if the VBA was activated before. The simplest way is to open and close the VBA Editor before starting presentation.

Greetings

Axel