【发布时间】:2017-12-02 09:04:45
【问题描述】:
我在 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
更新: 我仍在为此奋斗。似乎有些建议说要更新当前显示的图表,您需要在 DoEvents 下方使用:
SlideShowWindows(1).View.GotoSlide SlideSowWindows(1).View.CurrentShowPosition
但这不起作用。它退出任何正在运行的代码。所以第一个函数中的 Do/Loop 退出了,它不会继续进行第二次迭代。
【问题讨论】:
-
您是否检查过以确保对象在 Excel 和 Powerpoint 之间使用相同的界面?
-
您的更新:代码是否与代码完全相同?如果是这样,请检查后半部分的拼写,其中
SlideShowWindows拼写错误。 -
你四个月前问过这个问题,但没有答案:你解决过这个问题吗?
-
由于您是从页面更改事件触发 SpinTheChart,因此每次使用 .View.GoToSlide 时都会触发。建议:声明一个公共布尔值(我们称之为 bUpdating)。在 SpinTheChart 例程和 OnSlideShowPageChange 中设置为 True,仅当 bUpdating 为 False 时才运行代码
标签: vba excel powerpoint