Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Office automation Excel to Powerpoint

Status
Not open for further replies.

whoffman

Programmer
Jun 12, 2002
28
US
I have tried everything and looked everywhere but can't find the answer to this one. I am trying to copy a chart in Excel and paste it into a Powerpoint slide (using macros, of course) and I can't see a way to do it. DDEInitiate fails on my machine, it asks if I want to start MSProf.exe - when I say yes - it, too, fails.
I can do an app.activate, but I want to open a particular powerpoint file to start with (a template, sort of).
Any ideas? TIA!
 
This macro from: Marco Schreuder (found on Google) to export chart. You may have to change it for your needs.

Sub ExportChartToPowerPoint()
'
' This routine will export an embedded chart on
' the activesheet to a PowerPoint presentation
'
Dim bPPOpen As Boolean
Dim oPP As PowerPoint.Application
Dim oPPPresentation As PowerPoint.Presentation
Dim oPPSlide As PowerPoint.Slide

On Error Resume Next
Application.ScreenUpdating = False

' use current instance of PowerPoint
Set oPP = GetObject(, "PowerPoint.Application")
If Err = 0 Then

' use the (first) open presentation
Set oPPPresentation = oPP.Presentations(1)

' or create new presention
If Err <> 0 Then
Set oPPPresentation = oPP.Presentations.Add(True)
End If
Else
' Getobject returned an error so:
' open PowerPoint and create new presentation
Set oPP = CreateObject(&quot;PowerPoint.Application&quot;)
Set oPPPresentation = oPP.Presentations.Add(True)
End If

' Get the (embedded) chart we want to export
ActiveSheet.ChartObjects(1).Activate
ActiveChart.ChartArea.Copy

' Create new PP slide
Set oPPSlide = oPPPresentation.Slides.Add( _
oPPPresentation.Slides.Count + 1, ppLayoutTitleOnly)

' Copy chart To PP slide
oPPSlide.Shapes.Paste
With oPPSlide.Shapes(2)
.IncrementLeft -106.5
.IncrementTop -26.25
.ScaleWidth 1.62, msofalse, msoScaleFromTopLeft
.ScaleHeight 1.62, msofalse, msoScaleFromTopLeft
End With

oPP.Visible = True
ActiveSheet.Range(&quot;A1&quot;).Select
Application.ScreenUpdating = True
End Sub

-Radix lecti
 
Thanks, but it didn't work. I'm getting a compile error that says user defined type not defined. I guess I have to study up on user defined types.
 
OK duh! You need to add a reference to the application if you want to refer to it! Thanks - this helped me a lot. This is a GREAT resource for anyone wanting to take advantage of the power of most MS apps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top