Creating a Powerpoint with Graphs from Access

跟風遠走 提交于 2020-01-05 04:20:07

问题


I am trying to programmatically create a PowerPoint from graphs in Access. Ideally, when the graphs move over to PowerPoint they will become static pictures and not graphs still linked to the access data.

I have tried procedures such as:

 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

And I get an error message such as: Paste method failed.

Is there a better approach? And can it be forced to become a static image?

Thank you.


回答1:


Ok, I found a way to do it. I am still interested if anyone has a more elegant way, but for anyone else dealing with a similar problem:

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



回答2:


Yep, this is exactly the technique I use - and I spent days searching the web for solutions. Its not very elegant but it works and the nice thing is that you get an MS Graph object in Powerpoint so that users can easily apply their own styling , templates etc



来源:https://stackoverflow.com/questions/1040720/creating-a-powerpoint-with-graphs-from-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!