PC Review


Reply
Thread Tools Rate Thread

Copy/Export/Transfer charts from Excel to power point with VBA cod

 
 
=?Utf-8?B?S291bGxh?=
Guest
Posts: n/a
 
      30th Oct 2006
Hi I want to copy/export/transfer charts from Excel to powerpoint. I have a
workbook which contains 4 sheets with 2 charts in each sheet. I want each
chart to appear to a separate slide in power point. I want to do that with
VBA code. I already have some code put it doesnt works.
The ppt file opens ok but in the function gives an error "Object doesnt
support this property or method"

Sub openppt()

Dim pptapplication As Object
Dim pptopen As Object
Dim pptpath As String

pptpath = "C:\Test\THIS IS A TEST.ppt"

Set pptapplication = CreateObject("powerpoint.Application")
pptapplication.Visible = True
Set pptopen = pptapplication.Presentations.Open(Filename:=pptpath)

End Sub

Public Function Test()
Dim xl As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
'Dim i%

Set xl = New Excel.Application
Set wb = xl.Workbooks.Open("C:\Test\SEQS.xls")
Set ws = wb.Worksheets(1)

With ActiveWindow.Selection.SlideRange ****HERE IT GIVES THE ERROR ****
For i = 1 To 3
.Shapes("Rectangle 2").TextFrame.TextRange.Text = ws.Cells(i,
1).Value
.Shapes("Rectangle 3").TextFrame.TextRange.Text = ws.Cells(i,
2).Value
ActiveWindow.Presentation.PrintOut 1, 1
Next i
End With

Set ws = Nothing
wb.Close SaveChanges:=False
Set wb = Nothing
xl.Quit
Set xl = Nothing

End Function



 
Reply With Quote
 
 
 
 
=?Utf-8?B?QW5keSBXaWxsaWFtcw==?=
Guest
Posts: n/a
 
      30th Oct 2006
The problem is that once you've opened your excel application it becomes the
active object and so the code is trying to apply this line:-

With ActiveWindow.Selection.SlideRange

to Excel and not Powerpoint

If you rewrite your function so it includes the openppt subroutine and
change the line above to read:-

With pptapplication.ActiveWindow.Selection.SlideRange

I think it will work

Revised code is below:-

Public Function Test()
Dim xl As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
Dim pptapplication As Object
Dim pptopen As Object
Dim pptpath As String
'Dim i%

Set xl = New Excel.Application
Set wb = xl.Workbooks.Open("c:\Test\SEQS.xls")
Set ws = wb.Worksheets(1)

pptpath = "C:\Test\THIS IS A TEST.ppt"

Set pptapplication = CreateObject("powerpoint.Application")
pptapplication.Visible = True
Set pptopen = pptapplication.Presentations.Open(Filename:=pptpath)

With pptapplication.ActiveWindow.Selection.SlideRange
For i = 1 To 3
.Shapes("Rectangle 2").TextFrame.TextRange.Text = ws.Cells(i,
1).Value
.Shapes("Rectangle 3").TextFrame.TextRange.Text = ws.Cells(i,
2).Value
ActiveWindow.Presentation.PrintOut 1, 1
Next i
End With

Set ws = Nothing
wb.Close SaveChanges:=False
Set wb = Nothing
xl.Quit
Set xl = Nothing

End Function

HTH

Andy W

"Koulla" wrote:

> Hi I want to copy/export/transfer charts from Excel to powerpoint. I have a
> workbook which contains 4 sheets with 2 charts in each sheet. I want each
> chart to appear to a separate slide in power point. I want to do that with
> VBA code. I already have some code put it doesnt works.
> The ppt file opens ok but in the function gives an error "Object doesnt
> support this property or method"
>
> Sub openppt()
>
> Dim pptapplication As Object
> Dim pptopen As Object
> Dim pptpath As String
>
> pptpath = "C:\Test\THIS IS A TEST.ppt"
>
> Set pptapplication = CreateObject("powerpoint.Application")
> pptapplication.Visible = True
> Set pptopen = pptapplication.Presentations.Open(Filename:=pptpath)
>
> End Sub
>
> Public Function Test()
> Dim xl As Excel.Application
> Dim wb As Workbook
> Dim ws As Worksheet
> 'Dim i%
>
> Set xl = New Excel.Application
> Set wb = xl.Workbooks.Open("C:\Test\SEQS.xls")
> Set ws = wb.Worksheets(1)
>
> With ActiveWindow.Selection.SlideRange ****HERE IT GIVES THE ERROR ****
> For i = 1 To 3
> .Shapes("Rectangle 2").TextFrame.TextRange.Text = ws.Cells(i,
> 1).Value
> .Shapes("Rectangle 3").TextFrame.TextRange.Text = ws.Cells(i,
> 2).Value
> ActiveWindow.Presentation.PrintOut 1, 1
> Next i
> End With
>
> Set ws = Nothing
> wb.Close SaveChanges:=False
> Set wb = Nothing
> xl.Quit
> Set xl = Nothing
>
> End Function
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I export or copy charts to power point? =?Utf-8?B?S291bGxh?= Microsoft Excel Charting 2 30th Oct 2006 10:23 PM
Linking Excel charts to Power Point slides =?Utf-8?B?R2xlbm4=?= Microsoft Powerpoint 3 11th Oct 2006 08:21 PM
How to copy a picture from a website & transfer to power point =?Utf-8?B?Q2hpcXVpdGEgQ3J1dGNoZXI=?= Microsoft Powerpoint 1 2nd Jun 2006 07:21 PM
How to copy a picture from a website & transfer to power point =?Utf-8?B?Q2hpcXVpdGEgQ3J1dGNoZXI=?= Microsoft Powerpoint 2 2nd Jun 2006 05:41 PM
Copy multiple charts from Excel to Power Point =?Utf-8?B?R2VuZWY=?= Microsoft Excel Charting 1 2nd Mar 2005 01:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:22 AM.