在PowerPoint演示文稿中旋转3D图表

Dan*_*son 7 excel powerpoint vba excel-vba powerpoint-vba

我在Excel中创建了一个旋转3D图表的宏.我将图表复制到PowerPoint中,设置代码以在幻灯片显示时在PowerPoint中运行.代码运行,但我无法让它实际更改屏幕上显示的内容.幻灯片处于编辑模式时,图形会旋转.知道如何让代码不仅仅运行(我可以看到调试数字显示),但在演示模式下更新屏幕?我的代码是:

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
Run Code Online (Sandbox Code Playgroud)

更新:我还在打这个.似乎有些建议说更新当前显示的图表,您需要在DoEvents下面使用:

SlideShowWindows(1).View.GotoSlide SlideSowWindows(1).View.CurrentShowPosition
Run Code Online (Sandbox Code Playgroud)

但这不起作用.它退出正在运行的任何代码.因此,第一个函数中的Do/Loop退出,并且不会继续进行第二次迭代.

Axe*_*ter 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
Run Code Online (Sandbox Code Playgroud)

您熟悉 Powerpoint 演示过程中宏的其他问题吗?它们在这样的环境中非常脆弱,必须仔细测试其效果。

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

问候

阿克塞尔