Hi. I'm VERY new at VBA. I used the code below to try and export charts into a presentation. I'm running into 2 problems.
1). "User-defined type not defined". I don't know what this means.
2). I've managed to get the powerpoint application to open automatically but there is no slide. You have to actually click in the slide area to get the initial slide, then you need to do a paste to get the darn chart into the slide. Is there a more automated way to open powerpoint with an active slide and auto paste the chart in there?
Help!!!! I'm despirate!![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
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"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
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("PowerPoint.Application"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
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("A1"
.Select
Application.ScreenUpdating = True
End Sub
1). "User-defined type not defined". I don't know what this means.
2). I've managed to get the powerpoint application to open automatically but there is no slide. You have to actually click in the slide area to get the initial slide, then you need to do a paste to get the darn chart into the slide. Is there a more automated way to open powerpoint with an active slide and auto paste the chart in there?
Help!!!! I'm despirate!
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("PowerPoint.Application"
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("A1"
Application.ScreenUpdating = True
End Sub