2009-06-24 25 views
1

我試圖以編程方式從Access中的圖形創建PowerPoint。理想情況下,當圖形移動到PowerPoint時,它們將變成靜態圖片,而不是圖形仍然與訪問數據鏈接。使用來自Access的圖形創建Powerpoint

我試圖程序,如:

Private Sub Command1_click() 
    Dim pwrpnt as Object 
    Dim Presentation as Object 

    set pwrpnt = CreateObject("Powerpoint.Application") 
    pwrpnt.Activate 
    Set Presentation = pwrpnt.Presentation.Open("C:\test.ppt") 
    Me.Graph1.SetFocus 
    Runcommand acCmdcopy 

    Presentation.Slides(1).Shapes.Paste 
    set pwrpnt = Nothing 
    set Presentation = Nothing 
End Sub 

我得到一個錯誤信息,如:粘貼方法失敗。

有沒有更好的方法?它可以被迫成爲一個靜態圖像?

謝謝。

回答

4

好吧,我找到了一個方法來做到這一點。我如果任何人有一個更優雅的方式仍然有興趣,但對於其他人處理類似的問題:

Private Sub Command1_click() 
'Note: Sample only, in real code this should probably have something to save the 
'PPT file and then close the powerpoint application, not to mention some error handling, 
' and possibly some picture formatting, etc. 

Dim pwrpnt as PowerPoint.Application 
Dim Presntation as PowerPoint.Presentation 

Me.Graph0.Action = acOLECopy 
set pwrpnt = CreateObject("Powerpoint.Application") 
pwrpnt.Activate 
Set Presentation = pwrpnt.Presentations.Open("TemplateFile.ppt") 
pwrpnt.ActiveWindow.ViewType = ppViewSlide 

'This inserts it as a picture, just use .Paste to insert it as an actual chart. 
pwrpnt.ActiveWindow.View.PasteSpecial ppPasteEnhancedMetafile 
EndSub 
+1

你可以繼續並用複選標記接受你自己的答案。 – 2010-02-24 01:33:20

2

是的,這正是我使用的技術 - 我花了幾天尋找解決方案的網絡。它不是非常優雅,但它的工作原理和好處是,你可以在Powerpoint中獲得一個MS Graph對象,這樣用戶可以很容易地應用他們自己的樣式,模板等。

相關問題