A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Charts and Charting
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can I paste a chart from Excel into a powerpoint slide "Placeholde



 
 
Thread Tools Display Modes
  #1  
Old April 9th, 2009, 03:13 PM posted to microsoft.public.excel.charting
Mats Teir[_2_]
external usenet poster
 
Posts: 1
Default Can I paste a chart from Excel into a powerpoint slide "Placeholde

I have a macro to transfer Excel graphs into PowerPoint slides, which works
fine, but the pasted graphs (pictures) are (with original shape pasted across
teh slide. I would like them to get pasted into the "Placeholder" that is
automatically created on a new slide.
Anyone have an idea how to get this done?

Thanks in advance

Mats


Sub TransferGraphs()
'
' TransferGraphs Macro
' Transfer all graphs on selected worksheet as pictures to PPT file
'

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim PresentationFileName As Variant
Dim SlideCount As Long
Dim iCht As Integer
Dim sTitle As String

' Create instance of PowerPoint
Set PPApp = CreateObject("Powerpoint.Application")

' For automation to work, PowerPoint must be visible
' (alternatively, other extraordinary measures must be taken)
PPApp.Visible = True

' Create a presentation
Set PPPres = PPApp.Presentations.Add

PPApp.ActiveWindow.ViewType = ppViewSlide

For iCht = 1 To ActiveSheet.ChartObjects.Count
With ActiveSheet.ChartObjects(iCht).Chart

' get chart title
If .HasTitle Then
sTitle = .ChartTitle.Text
Else
sTitle = ""
End If

' remove title (or it will be redundant)
.HasTitle = False

' copy chart as a picture
.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture

' restore title
If Len(sTitle) 0 Then
.HasTitle = True
.ChartTitle.Text = sTitle
End If
End With

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutObject)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
' align the chart TO THE MIDDLE OF THE SLIDE AND INSERT THE SLIDE
TITLE (COPIED FROM THE GRAPH)
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
.Shapes.Placeholders(1).TextFrame.TextRange.Text = sTitle
End With

Next

' Save and close presentation
With PPPres
.SaveAs "C:\MACROTEST\MACROTEST.ppt"
.Close
End With

' Quit PowerPoint
' PPApp.Quit

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

End Sub

  #2  
Old April 9th, 2009, 06:26 PM posted to microsoft.public.excel.charting
Jon Peltier
external usenet poster
 
Posts: 5,018
Default Can I paste a chart from Excel into a powerpoint slide "Placeholde

I don't think you can paste it "in" the placeholder, but I'm sure you can
adjust your code to determine the size and position of the placeholder, and
resize and reposition the pasted chart accordingly.

- Jon
-------
Jon Peltier, Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
Advanced Excel Conference - Training in Charting and Programming
http://peltiertech.com/Training/2009...00906ACNJ.html
_______


"Mats Teir" wrote in message
...
I have a macro to transfer Excel graphs into PowerPoint slides, which works
fine, but the pasted graphs (pictures) are (with original shape pasted
across
teh slide. I would like them to get pasted into the "Placeholder" that is
automatically created on a new slide.
Anyone have an idea how to get this done?

Thanks in advance

Mats


Sub TransferGraphs()
'
' TransferGraphs Macro
' Transfer all graphs on selected worksheet as pictures to PPT file
'

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim PresentationFileName As Variant
Dim SlideCount As Long
Dim iCht As Integer
Dim sTitle As String

' Create instance of PowerPoint
Set PPApp = CreateObject("Powerpoint.Application")

' For automation to work, PowerPoint must be visible
' (alternatively, other extraordinary measures must be taken)
PPApp.Visible = True

' Create a presentation
Set PPPres = PPApp.Presentations.Add

PPApp.ActiveWindow.ViewType = ppViewSlide

For iCht = 1 To ActiveSheet.ChartObjects.Count
With ActiveSheet.ChartObjects(iCht).Chart

' get chart title
If .HasTitle Then
sTitle = .ChartTitle.Text
Else
sTitle = ""
End If

' remove title (or it will be redundant)
.HasTitle = False

' copy chart as a picture
.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture

' restore title
If Len(sTitle) 0 Then
.HasTitle = True
.ChartTitle.Text = sTitle
End If
End With

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutObject)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
' align the chart TO THE MIDDLE OF THE SLIDE AND INSERT THE SLIDE
TITLE (COPIED FROM THE GRAPH)
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
.Shapes.Placeholders(1).TextFrame.TextRange.Text = sTitle
End With

Next

' Save and close presentation
With PPPres
.SaveAs "C:\MACROTEST\MACROTEST.ppt"
.Close
End With

' Quit PowerPoint
' PPApp.Quit

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

End Sub



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:14 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.