Batch importing excel graphs into powerpoint presentation

G

Guest

Hi,
I'm a newbie user running office 2003
I would like to batch import 100 graphs from 100 different excel files to
powerpoint presentation using macro (one graph per slide). How would i set up
such macro?

I've tried the following codes but it would only update one gaph at a time
with no control over where the gaph comes from and which slide it will go to.

Thanks

Sub ChartToPresentation()
' Uses Early Binding to the PowerPoint Object Model
' Set a VBE reference to Microsoft PowerPoint Object Library

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide

' Make sure a chart is selected
If ActiveChart Is Nothing Then
MsgBox "Please select a chart and try again.", vbExclamation, _
"No Chart Selected"
Else
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
' Reference active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)

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

' Paste chart
PPSlide.Shapes.Paste.Select

' Align pasted chart
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

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

End Sub

------------------------
 
B

Brian Reilly, MVP

You aren't changing the sheet choice in Excel to copy a new chart,
You'd want to loop through the spreadsheet with something like

Dim i as Interger

With activeworkbook.sheets.count
With activeworkbook.sheets(i)
'check if you only have a single chart on a sheet
'No reason to select it just reference it and copy it

'run most of your other code





End with
Next i
End With

Not at all tested. Time for me to go back to sleep.

Brian Reilly, MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top