2009-06-24 24 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对象,这样用户可以很容易地应用他们自己的样式,模板等。

相关问题