views:

787

answers:

3

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.

+2  A: 

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
TimothyAWiseman
you can go ahead and accept your own answer with the check mark.
Otaku
Thanks, didn't realize that.
TimothyAWiseman
+2  A: 

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

Chris
A: 

If you could help me out, I am new to to this type of programming. I am not sure why I am getting errors on your code. Please assist:
Compile error: User-defined type not defined Dim pwrpnt As PowerPoint.Application

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

pwrpnt.ActiveWindow.View.PasteSpecial ppPasteEnhancedMetafile.Paste EndSub

Mike
Ummm... you want to take this and make it it's own question. It looks like you've created one yesterday, but you didn't include enough info in it to be sure.
CodeSlave