This code snippet illustrates the manner in which
PowerPoint can be automated from any external application. In this
example a slide in inserted into a new presentation and then an image is
imported into the slide and scaled to it's original size.
You can run this code from any Office application or
Visual Basic® but don't forget to add a reference in the project to the
PowerPoint object library and the Office object library.
Top
'
--------------------------------------------------------------------------------
' Copyright ©1999-2007, Shyam Pillai, All Rights Reserved.
'
--------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
'
--------------------------------------------------------------------------------
Sub InsertGraphicOnSlide()
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim ppShape As PowerPoint.Shape
Dim ppCurrentSlide As PowerPoint.Slide
Set ppApp = CreateObject("PowerPoint.Application")
ppApp.Visible = True
Set ppPres = ppApp.Presentations.Add(msoTrue)
Set ppCurrentSlide = ppPres.Slides.Add(Index:=1, _
Layout:=ppLayoutBlank)
With ppCurrentSlide.Shapes
' Adds a picture to slide 1 in the active presentation.
Set oPicture = .AddPicture("D:\Area 51\Images\test.jpg", _
msoFalse, msoTrue, 0, 0, 1, 1)
' Now scale the image
oPicture.ScaleHeight 1, msoTrue
oPicture.ScaleWidth 1, msoTrue
End With
End Sub
Top
|