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
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
--
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...
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...
Regards,
Brian Reilly, PowerPoint MVP, just like Shyam,
Echo
Brian Reilly, PowerPoint MVP
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...
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...