Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating a slide from Excel

809 views
Skip to first unread message

Eric Jeanne

unread,
Oct 31, 2000, 6:37:56 PM10/31/00
to

Hi everybody.

I'm trying to create a slide from VBA Excel.

In PowerPoint, this instruction works fine :
Set newSl = ActivePresentation.Slides.Add(nb + 1, ppLayoutBlank)
But in VBA Excel, this one crashes :
Set newSl = myPptApp.ActivePresentation.Slides.Add(nb + 1, ppLayoutBlank)
with this error : " -2147024809 : Slides.Add = invalid enumeration value"

The whole sub is this one (I want to create a new slide to put in an Excel
sheet).
---------------------------------------------------------------
Sub PptExcelChart()
appli = "PowerPoint.application"
cheminPpt = "C:\WINDOWS\Bureau\PrésentationExcel.ppt" 'Excel wkbk path
cheminXL = "C:\WINDOWS\Bureau\Excel pour Ppt.xls" 'Ppt file path
On Error Resume Next
Set myPptApp = GetObject(, appli)
errN = Err.Number
On Error GoTo 0
If errN = 429 Then Set myPptApp = _
CreateObject(appli)

Set myPptobj = GetObject(cheminPpt)
myPptApp.Visible = True

Set nouvelleDiapo = myPptApp.ActivePresentation.Slides.Add(nb + 1,
ppLayoutBlank)
'AND THEN GOTO
'OR Direct GOTO
'myPptApp.ActiveWindow.View.GotoSlide _
Index:=myPptApp.ActivePresentation.Slides.Add _
(Index:=nb + 1, Layout:=ppLayoutBlank).SlideIndex

myPptApp.ActiveWindow.Selection.SlideRange. _
Shapes.AddOLEObject(Left:=120#, Top:=110#, _
Width:=480#, Height:=320#, Filename:= _
cheminXL, Link:=msoTrue).Select
End Sub
---------------------------------------------------------------
Without creating a new slide, it works fine by creating the chart on the
selected slide.

Any help would be appreciated. TIA.
--
Eric Jeanne


Eric Jeanne

unread,
Oct 31, 2000, 6:42:42 PM10/31/00
to
Sorry, one line is missing in the sub :
nb = myPptApp.ActivePresentation.Slides.Count

before creating the new slide.

But I only forgot it when copying the sub on the news group.
Even with this line, the Excel macro crashes.

--
Eric Jeanne


Shyam Pillai

unread,
Nov 1, 2000, 8:53:05 AM11/1/00
to

Eric,
ppLayoutBlank is a defined enumerated constant set at value = 2. In your
code I don't see any declaration of ppLayoutBlank value set as 2, which
therefore get's passed to PowerPoint as 0. There exists no constant in the
enumerated set of Layout's which has a value 0 hence you encounter the
error.
Make a declaration in the code
Private Const ppLayoutBlank=2
it should work. Also your code could use some refinement. I shall post that
later.

--
Regards
Shyam Pillai

http://officetips.homepage.com

Please reply in newsgroup - No email replies .

...

"Eric Jeanne" <eje...@club-internet.fr> wrote in message
news:#cfsbN5QAHA.200@cppssbbsa03...

Eric Jeanne

unread,
Nov 1, 2000, 3:48:09 PM11/1/00
to

Shyam (or Pillai !?)

Thanks for your answer.
You are right because I didn't set the VBE reference to Microsoft PowerPoint
Object Library before exceuting the code. So, Excel didn't know what
ppLayoutBlank meant.

Best regards.

--
Eric Jeanne
Shyam Pillai <Sh...@Asia.com> a écrit dans le message :
edK1GpA...@cppssbbsa02.microsoft.com...

Brian Reilly, MVP

unread,
Nov 1, 2000, 4:31:06 PM11/1/00
to

Eric, His name is Shyam Pillai. Shyam is his first name like your's is
Eric, or is it Jeanne?
No offense taken, we're just a lot of friends (or is that fiends) here
and like to have fun. Glad Shyam, one of the, if not the, best VBA
experts here, and more polite than I am, but equally as shy (g),
helped you out.
Stop in again.

Regards,
Brian Reilly, PowerPoint MVP, just like Shyam,

echos

unread,
Nov 1, 2000, 8:16:33 PM11/1/00
to
Brian, you fiend! D'ya wanna drive Eric off permanently?
Eric (Jeanne? <G>), don't mind Brian. He's our resident chain-yanker, hehehe.

Echo

Brian Reilly, MVP

unread,
Nov 1, 2000, 11:32:53 PM11/1/00
to

Echo, Nah, Jeanne is OK with me, my wife's boyfriend when I met her 20
odd years ago was and still is named Jeanne (first name). Hence the
comment And he's still a friend and she's still my wife.

Brian Reilly, PowerPoint MVP

Shyam Pillai

unread,
Nov 1, 2000, 11:44:39 PM11/1/00
to

Eric,
Don't mind Brian, that's his way of welcoming you here. Nice to know that it
worked for you. However there are a few points which you might find useful,

Set myPptobj = GetObject(cheminPpt)
instead of the above line you could also use.
Set myPptobj = myPptApp.Presentations.Open(cheminPpt)
--------------------


Set nouvelleDiapo = myPptApp.ActivePresentation.Slides.Add(nb +
1,ppLayoutBlank)

Since we already have a reference to the file (myPptobj) we could also use

Set nouvelleDiapo = myPptObj.Slides.Add(nb + 1, ppLayoutBlank)
----------------
You don't necessarily need to move to a slide to add a shape to it.
You could reference it as so.

myPptobj.Slides(<Put SlideIndex Here> ) _
.Shapes.AddOLEObject 120#, 110#, 480#, 320#, _
Filename:= cheminXL, Link:=msoTrue

Since you are using Automation, you will find it useful to read some
articles which discuss the differences between Early Binding and Late
Binding

INFO: Using Early Binding and Late Binding in Automation
http://support.microsoft.com/support/kb/articles/Q245/1/15.asp

There is also a Help File which discusses Automation in various Office Apps
(with good examples) in the MS downloads section.

--
Regards
Shyam Pillai

http://officetips.homepage.com

Please reply in newsgroup - No email replies .

...

"Eric Jeanne" <eje...@club-internet.fr> wrote in message

news:#Yo7OTERAHA.195@cppssbbsa04...

Eric Jeanne

unread,
Nov 2, 2000, 1:29:23 PM11/2/00
to

Thanks a lot Brian and Shyam.

I use to post on microsoft.public.fr.excel (french newsgroup for excel)
where we are a jolly good team of cool guys (and girls). I think we do there
a good work, but - as you do -we keep a good part of our time and our posts
to joke and laugh : it's the best way to get good results. Can I add that
last year I met three persons of our newsgroup, and about ten in june and
july. In december the next meeting (at the restaurant !) will gather about
twenty excellers from FRance and Belgium in Paris. Virtual is good but Real
life is also very nice !

So no problem. I'm happy to know that good humour and jokes are also present
on this newsgroup.

Shyam, I'm gonna have a look to your last post.

Thanks again.

--
Eric Jeanne
Shyam Pillai <Sh...@Asia.com> a écrit dans le message :

u$MH$7LRAHA.72@cppssbbsa03...

0 new messages