Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using VBA to copy a Chartsheet to Powerpoint

I have written code for users to specify a worksheet and range or named range
that is then copied to PowerPoint Slides.

For example: If a Chart is on a Sheet named "Revenue" and in cells B4:T64,
the user just adds "Revenue" and "B4:T64". It works the same if the range of
cells are named.

This works fine for Charts embedded in a worksheets but if a Chart is on a
Chartsheet I don't have a range or name to reference. I thought it was just
Chart1, Chart2, etc. but that doesn't seem to work.
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Using VBA to copy a Chartsheet to Powerpoint

Here is an example that I use...

Option Explicit

Private PPApp As PowerPoint.Application
Private PPPres As PowerPoint.Presentation
Private PPSlide As PowerPoint.Slide
Private PPShape As PowerPoint.Shape
Private sCnt&
Private chartWS As Chart
Private chartWB, dataWB As Workbook

Public Sub pptMacro()

Dim CheckStr$, dataDir$

Set chartWB = Application.ThisWorkbook
Set chartWS = ActiveSheet
chartWB.Sheets(chartWS.Name).CopyPicture Appearance:=xlPrinter,
Format:=xlPicture
Call openPPT
Call paste2PPT
Call closePPT
ThisWorkbook.Activate
Sheets(chartWS.Name).Activate
Exit Sub

no_data:

Call closePPT
End Sub


Private Sub openPPT()
Set PPApp = CreateObject("Powerpoint.Application.11")
PPApp.Activate
PPApp.Presentations.Open ThisWorkbook.Path & "\Template
\template.ppt"

With PPApp.ActivePresentation
.SaveAs ThisWorkbook.Path & "\the_new_file_name.ppt"
End With
End Sub

Private Sub closePPT()
'set to normal view before save/close
PPApp.ActiveWindow.ViewType = ppViewNormal
With PPApp.ActivePresentation
.Save
.Close
End With

PPApp.Quit

Set PPShape = Nothing
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

End Sub


Private Sub paste2PPT()
' Paste chart
With PPApp.ActiveWindow
.ViewType = ppViewSlide
.View.Paste
End With

' Align pasted chart
sCnt = PPApp.ActiveWindow.Selection.SlideRange.Shapes.Cou nt
Set PPShape = PPApp.ActiveWindow.Selection.SlideRange.Shapes(sCn t)
PPShape.Select
PPShape.ZOrder msoSendToBack 'by sending to the back it now
becomes index:=1

PPApp.ActiveWindow.Selection.Unselect

End Sub




HTH—Lonnie


On Jun 2, 4:45*pm, MMD wrote:
I have written code for users to specify a worksheet and range or named range
that is then copied to PowerPoint Slides. *

For example: If a Chart is on a Sheet named "Revenue" and in cells B4:T64,
the user just adds "Revenue" and "B4:T64". *It works the same if the range of
cells are named.

This works fine for Charts embedded in a worksheets but if a Chart is on a
Chartsheet I don't have a range or name to reference. *I thought it was just
Chart1, Chart2, etc. but that doesn't seem to work.
Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using VBA to copy a Chartsheet to Powerpoint

This is good but it doesn't quite get me there. A user may have a wb with
many sheets in it but they only need to pull info from only some of the
sheets.
My utility allows them to specify which sheet and which cells to grab using
the Tab name and a range of data they want. They specify this data in the
utility before clicking on a button to execute the grab and paste. The code
reads this info and copies it to PowerPoint.
But currently they cannot use it for Chartsheets that are seperate tabs but
do not contain the usual worksheet grid.

"Lonnie M." wrote:

Here is an example that I use...

Option Explicit

Private PPApp As PowerPoint.Application
Private PPPres As PowerPoint.Presentation
Private PPSlide As PowerPoint.Slide
Private PPShape As PowerPoint.Shape
Private sCnt&
Private chartWS As Chart
Private chartWB, dataWB As Workbook

Public Sub pptMacro()

Dim CheckStr$, dataDir$

Set chartWB = Application.ThisWorkbook
Set chartWS = ActiveSheet
chartWB.Sheets(chartWS.Name).CopyPicture Appearance:=xlPrinter,
Format:=xlPicture
Call openPPT
Call paste2PPT
Call closePPT
ThisWorkbook.Activate
Sheets(chartWS.Name).Activate
Exit Sub

no_data:

Call closePPT
End Sub


Private Sub openPPT()
Set PPApp = CreateObject("Powerpoint.Application.11")
PPApp.Activate
PPApp.Presentations.Open ThisWorkbook.Path & "\Template
\template.ppt"

With PPApp.ActivePresentation
.SaveAs ThisWorkbook.Path & "\the_new_file_name.ppt"
End With
End Sub

Private Sub closePPT()
'set to normal view before save/close
PPApp.ActiveWindow.ViewType = ppViewNormal
With PPApp.ActivePresentation
.Save
.Close
End With

PPApp.Quit

Set PPShape = Nothing
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

End Sub


Private Sub paste2PPT()
' Paste chart
With PPApp.ActiveWindow
.ViewType = ppViewSlide
.View.Paste
End With

' Align pasted chart
sCnt = PPApp.ActiveWindow.Selection.SlideRange.Shapes.Cou nt
Set PPShape = PPApp.ActiveWindow.Selection.SlideRange.Shapes(sCn t)
PPShape.Select
PPShape.ZOrder msoSendToBack 'by sending to the back it now
becomes index:=1

PPApp.ActiveWindow.Selection.Unselect

End Sub




HTH€”Lonnie


On Jun 2, 4:45 pm, MMD wrote:
I have written code for users to specify a worksheet and range or named range
that is then copied to PowerPoint Slides.

For example: If a Chart is on a Sheet named "Revenue" and in cells B4:T64,
the user just adds "Revenue" and "B4:T64". It works the same if the range of
cells are named.

This works fine for Charts embedded in a worksheets but if a Chart is on a
Chartsheet I don't have a range or name to reference. I thought it was just
Chart1, Chart2, etc. but that doesn't seem to work.
Thanks!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 and chart as chartsheet Bob Flanagan[_2_] Charts and Charting in Excel 1 August 19th 08 11:32 PM
Copy charts to powerpoint Graham Whitehead Excel Programming 3 July 4th 08 11:35 PM
Is it possible to hyperlink from a worksheet to a chartsheet? kippers Charts and Charting in Excel 1 January 16th 07 12:15 PM
RangeFromPoint ... on a chartsheet ? MrT Excel Programming 4 June 19th 06 02:29 PM
1 ChartSheet, 10 worksheets Martin Wheeler Charts and Charting in Excel 3 January 22nd 05 09:22 PM


All times are GMT +1. The time now is 01:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"