VBA between excel and powerpoint

G

Guest

Hi - I need some help.

I'm new to VBA.

My problem is that I in Excel need to make a picture copy of a diagram and
then post it in a new slide in a open powerpoint presentation.

But how do i write code in a Excel makro to work in Powerpoint?

Br Kent
 
B

Bob Phillips

Here is a simple example that paste the activechart in

Sub CreatePowerPoint()
Dim oPPApp As Object
Dim oPPPres As Object
Dim oPPSlide As Object

Set oPPApp = CreateObject("Powerpoint.Application")

Set oPPPres = oPPApp.Presentations.Add
oPPApp.Visible = True

oPPApp.ActiveWindow.ViewType = 1 'ppViewSlide

Set oPPSlide = oPPPres.Slides.Add(1, 11) 'ppLayoutTitleOnly

ActiveChart.CopyPicture Appearance:=xlScreen, _
Size:=xlScreen, _
Format:=xlPicture

oPPSlide.Shapes.Paste.Select

oPPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
oPPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
N

Nick Hodge

Kent

Here's the theory. It uses early binding, so you will need to set a
reference to the PowerPoint library through Tools>References.. in the Excel
VBE. I used a diagram 2 on sheet1 in Excel

Sub AutomatePowerPoint()
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Dim xlDiagram As Shape

Set ppApp = New PowerPoint.Application
Set ppPres = ppApp.Presentations.Add
Set ppSlide = ppPres.Slides.Add(1, ppLayoutBlank)
Set xlDiagram = Worksheets("Sheet1").Shapes("Diagram 2")

ppApp.Visible = msoTrue

xlDiagram.Copy

ppSlide.Shapes.Paste

Set xlDiagram = Nothing
Set ppSlide = Nothing
Set ppPres = Nothing
Set ppApp = Nothing
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
www.nickhodge.co.uk
 
B

Bob Phillips

msoTrue instead of True. Interesting ....

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
N

Nick Hodge

Bob

I thought it strange too, but I know so little about the PP object model I
went with the 'boolean' intellisense gave me!

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
www.nickhodge.co.uk
 
G

Guest

This worked - Thanks a lot..

I can not get the "Dim as a Powerpoint.Application to work, but the Object
dose.
 
G

Guest

Kind of makes you wonder at what point in time
TRUE <> msoTrue
will become True (or msoTrue, depending?)
If nothing else, it serves as a reminder that you're working within the mso
library rather than the application's?

But I digress, and offer nothing additional for the OP, so I shall leave
now...
 
N

Nick Hodge

Kent

As I outlined, mine uses early binding so you have to add the reference
manually in advance. I prefer early binding as it speeds my coding because
I get intellisense. Also as I start with managed code it is stronger typed
and good current practice.

However as Bob's code worked...that's all that matters

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
www.nickhodge.co.uk
 
B

Bob Phillips

Kent,

To use Nick's code, you have to go into Tools>References in the VBIDE, and
check the Microsoft PowerPoint library item.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
B

black_sun

Hi,
I used your routine and it works very well.
I made a change: I don't paste a chart but a range ex: A1:AZ90 but I
have a problem.
It pastes not the whole selection range but only a little part of it.

How can I paste the whole selection?

Thanks a lots

Denis



Bob Phillips ha scritto:
 

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