borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (tulong mga kbyan!!!!!)Next Topic (Help with Excel scripting for calculation of a unknown column length) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Excel chart to powerpoint
Poster Message
confusedbrat
Level: Sage

Registered: 29-08-2005
Posts: 64

icon Excel chart to powerpoint

I am trying to get a list of excel files in a sheet and trying to add all the charts to a powerpoint. I do not even know if this should work this way but then when i run it it gives me a script 9 out of range error. Can someone tell me a better way to do this.

Also if i need few charts and not all and if i list them on sheet1., how can i get them in powerpoint.


Thanksssssssssssssssss
Brat



Sub Chart2PPT()

'Declarations

Dim objPPT As Object
Dim objPrs As Object
Dim shtTemp As Worksheet
Dim chtTemp As Chart
Dim intSlide As Integer
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String

'Delete existing powerpoint slide
Set FSO = New FileSystemObject
If FSO.FileExists("\\Kpserver4\metrics\metrics.ppt") Then
Kill ("\\Kpserver4\metrics\metrics.ppt")
End If

'get count of number of workbooks to be imported
chartnum = 1
For I = 1 To 100
If Sheet1.Cells(I, 1) <> "" Then
chartnum = chartnum + 1
End If
Next I


'Create New powerpoint slide
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
objPPT.presentations.Add
objPPT.ActiveWindow.ViewType = 1 'ppViewSlide

For I = 2 To chartnum

wrkbk = Sheet1.Cells(I, 1)

Workbooks.Open (wrkbk & ".xls")
Workbooks(wrkbk & ".xls").Activate

'Add graphs from existing power point
For Each chtTemp In ActiveWorkbook.Charts
intSlide = intSlide + 1
With chtTemp
.Activate
.ChartArea.Select
.CopyPicture
End With
If intSlide > objPPT.presentations(1).Slides.Count Then
objPPT.ActiveWindow.View.GotoSlide Index:=objPPT.presentations(1).Slides.Add(Index:=intSlide, Layout:=1).SlideIndex
Else
objPPT.ActiveWindow.View.GotoSlide intSlide
End If
objPPT.ActiveWindow.View.Paste
Next

Workbooks(wrkbk & ".xls").Close
Workbooks("\\Kpserver4\metrics\Update metrics.xls").Activate
Next I

'Save powerpoint and close
objPPT.presentations(1).SaveAs ("\\Kpserver4\metrics\metrics.ppt")
objPPT.Quit
Set objPrs = Nothing
Set objPPT = Nothing

End Sub

12-02-2007 at 04:29 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Excel chart to powerpoint
Previous Topic (tulong mga kbyan!!!!!)Next Topic (Help with Excel scripting for calculation of a unknown column length) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder