Forestq

Active Member
Joined
May 9, 2010
Messages
482
Hi,

I want to copy chart from excel to powerpoint and paste as image:
Code:
Dim wb As Workbook
Dim ws2 As Worksheet


Set wb = ActiveWorkbook
Set ws2 = wb.Worksheets("C2")


Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
     
Set newPowerPoint = New PowerPoint.Application
newPowerPoint.Presentations.Add


newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutBlank
newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)


'********************************************* C2
ws2.ChartObjects("Chart 1").Select
ActiveChart.ChartArea.Copy
activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
[code]

I got error: run-time error '424':
object required

what I have wrong??
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
There's no need to select...

Code:
activeSlide.Shapes.PasteSpecial DataType:=ppPasteMetafilePicture

To set properties...

Code:
[COLOR=darkblue]Dim[/COLOR] pptShape [COLOR=darkblue]As[/COLOR] PowerPoint.Shape

[COLOR=darkblue]Set[/COLOR] pptShape = activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture)(1)

[COLOR=green]'set properties[/COLOR]
[COLOR=darkblue]With[/COLOR] pptShape
    .Left = 25
    .Top = 25
    [COLOR=green]'etc[/COLOR]
    '
    '
    [COLOR=green]'[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]

Note that PasteSpecial returns a ShapeRange, hence the use of (1). As such a Shape object is returned, which is assigned to the object variable pptShape.

Hope this helps!
 
Last edited:
Upvote 0
Try something like this...

Code:
[color=darkblue]Dim[/color] oTextBox [color=darkblue]As[/color] PowerPoint.Shape

[color=darkblue]Set[/color] oTextBox = activeSlide.Shapes.AddTextbox( _
    Orientation:=msoTextOrientationHorizontal, _
    Left:=25, _
    Top:=25, _
    Width:=150, _
    Height:=200)

[color=darkblue]With[/color] oTextBox
    .TextFrame.TextRange.Characters.Text = "Your text here"
    [color=darkblue]With[/color] .Line
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 0, 0)
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]With[/color] .Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(255, 255, 0)
    [color=darkblue]End[/color] With
End With

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top