7

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.

4

2 回答 2

1

如果图表在编辑模式下旋转,为什么不将其记录为 .GIF 并包含在演示文稿中?

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

录制屏幕:http ://www.screentogif.com

于 2016-02-10T12:18:22.030 回答
0

图表上的更改似乎不会触发 SlideShowView 刷新。但是形状中文本的更改会做到这一点。因此,以下代码旋转图表:

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

您熟悉在 powerpoint 演示期间使用宏的其他问题吗?它们在这样的环境中非常脆弱,必须仔细测试它们的影响。

并且 OnSlideShowPageChange 仅在之前激活 VBA 时才有效。最简单的方法是在开始演示之前打开和关闭 VBA 编辑器。

问候

阿克塞尔

于 2014-08-16T19:42:29.363 回答