M
My Own IT dept
Jon,
First let me say that I am a complete novice when it comes to using VBE. I
feel as if I'm in another counrty, don't understand the language and am using
hand gestures and grunting to try to get my problem solved. I'm missing some
basic understanding of how this whole system works. That said...
I'm trying to copy multiple charts (1 per worksheet) from a range of
worksheets.
I highlight the range of WS tabs and run the macro (F5). I get no error
message but nothing happens (no charts copied). I have a PPT document open
with more than enough blank pages (although I don't think that's necessary
based on what I think I read in the code).
Is there something else I should be doing?
Here is the code that I entered into the VBE editor (should look very
familiar):
Sub ChartstoPresentation()
' Set a VBE reference to Microsoft PowerPoint Object Library
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
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
For iCht = 1 To ActiveSheet.ChartObjects.Count
' copy chart as a picture
ActiveSheet.ChartObjects(iCht).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
' position the chart
With PPApp.ActiveWindow.Selection.ShapeRange
.Top = 94 ' points
.Left = 58 ' points
.Width = 8.2 * 72
.Height = 5.6 * 72
End With
End With
Next
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
-----
Any suggestions?
Thanks very much.
First let me say that I am a complete novice when it comes to using VBE. I
feel as if I'm in another counrty, don't understand the language and am using
hand gestures and grunting to try to get my problem solved. I'm missing some
basic understanding of how this whole system works. That said...
I'm trying to copy multiple charts (1 per worksheet) from a range of
worksheets.
I highlight the range of WS tabs and run the macro (F5). I get no error
message but nothing happens (no charts copied). I have a PPT document open
with more than enough blank pages (although I don't think that's necessary
based on what I think I read in the code).
Is there something else I should be doing?
Here is the code that I entered into the VBE editor (should look very
familiar):
Sub ChartstoPresentation()
' Set a VBE reference to Microsoft PowerPoint Object Library
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
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
For iCht = 1 To ActiveSheet.ChartObjects.Count
' copy chart as a picture
ActiveSheet.ChartObjects(iCht).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
' position the chart
With PPApp.ActiveWindow.Selection.ShapeRange
.Top = 94 ' points
.Left = 58 ' points
.Width = 8.2 * 72
.Height = 5.6 * 72
End With
End With
Next
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
-----
Any suggestions?
Thanks very much.
Jon Peltier said:I don't recall now, and if I recalled then I'd probably have mentioned it.
To get back to your original question, you could adjust the pasted object's
size and position:
With PPSlide
' paste and select the chart picture
.Shapes.Paste.Select
' align the chart
With PPApp.ActiveWindow.Selection.ShapeRange.
.Top = [some value]
.Left = [some value]
.Height = [some value]
.Width = [some value]
End With
- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______
My Own IT dept said:Jon,
I've tried to find that other forum in which you said how to set the
desired
chart size right in Excel, but can't. Please let me know which one it is.
Thanks.