2013-10-22 85 views
7

我在Excel中創建了一個可以旋轉3D圖表的宏。我將圖表複製到PowerPoint中,將代碼設置爲在幻燈片顯示時在PowerPoint中運行。代碼運行,但我無法實際改變屏幕上顯示的內容。幻燈片處於編輯模式時,圖形將旋轉。任何想法如何讓代碼不只是運行(我可以看到調試數字顯示),但更新屏幕時,在演示模式?我的代碼是:在PowerPoint演示文稿中旋轉3D圖表

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 

更新: 我還在爲此而戰。這似乎有些recomendations說來更新當前顯示的圖表,你需要使用時,下面的DoEvents:

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

但這不起作用。它退出正在運行的任何代碼。所以第一個函數中的Do/Loop被退出,並且不會繼續執行第二次迭代。

+1

你檢查,以確保對象使用Excel和PowerPoint中的相同的接口? –

+1

是您的更新:從代碼中精確複製代碼?如果是這樣,請檢查下半部分的拼寫,其中'SlideShowWindows'拼寫錯誤。 –

+0

四個月前你問過這個問題,但沒有答案:你有沒有解決過這個問題? –

回答

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編輯器。

問候

阿克塞爾

+0

我很想知道這是否有效。 – peege

+0

適用於PowerPoint 2007。當然,名稱必須是正確的。用3張幻燈片創建一個新的PPT演示文稿。在第二張幻燈片上有一個標題形狀和一個3D圖形。打開VBA編輯器。將代碼複製到模塊中。將「Slide1」更改爲「Slide2」。步驟通過'公共Sub SpinTheChart()'直到'設置oSlide = ActivePresentation.Slides(「Slide2」)'。在本地窗口中查找哪個名稱具有oSlide-Shapes-Item2。在'Set oChart = oSlide.Shapes(「Diagramm 4」)。Chart'中替換這個名字。保存VBA。關閉VBA編輯器。現在它應該以演示模式運行。 –

相關問題