Creating Powerpoint with Charts from Access

I am trying to programmatically create PowerPoint from graphs in Access. Ideally, when the charts switch to PowerPoint, they will become static images, not charts still associated with access data.

I tried procedures like:

 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, for example: Paste method failed.

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

Thanks.

+1
source share
2 answers

Ok, I found a way to do this. I am still interested in if someone has a more elegant way, but for someone who is 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
+4

, , , . , , , MS Graph Powerpoint, , ..

+2

Source: https://habr.com/ru/post/1708512/


All Articles