1

我正在尝试以编程方式从 Access 中的图形创建 PowerPoint。理想情况下,当图表移动到 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

2 回答 2

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
于 2009-06-25T23:52:56.140 回答
2

是的,这正是我使用的技术——我花了几天时间在网上搜索解决方案。它不是很优雅,但很有效,而且好处是您在 Powerpoint 中获得了一个 MS Graph 对象,以便用户可以轻松应用自己的样式、模板等

于 2009-07-29T18:43:55.993 回答