我正在尝试以编程方式从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
我收到一条错误消息,例如:粘贴方法失败。
有更好的方法吗?它可以被迫成为静态图像吗?
谢谢。
答案 0 :(得分: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 :(得分:2)
是的,这正是我使用的技术 - 我花了几天时间在网上搜索解决方案。它不是很优雅,但它很有效,而且好处是你在Powerpoint中获得了一个MS Graph对象,这样用户就可以轻松地应用自己的样式,模板等