April 2006
Beginner
1114 pages
98h 16m
English
You can use the same steps to automate PowerPoint that you used to automate Word from Excel. PowerPoint has two creatable objects: Application and Presentation, but only the Application object exposes events.
The following code demonstrates how to create a new slide in a presentation using a selected range of cells from Excel:
' Worksheet class. Dim WithEvents m_ppt As PowerPoint.Application Dim m_pres As PowerPoint.Presentation Sub StartPPT( ) Set m_ppt = New PowerPoint.Application m_ppt.Visible = True End Sub Sub PasteRangeToPPT( ) Dim sld As PowerPoint.Slide, sh As PowerPoint.Shape ' If a range of cells is selected. If TypeName(Selection) = "Range" Then ' Start PowerPoint if it's not already running. If m_ppt Is Nothing Then StartPPT ' Copy the selected cells. Selection.Copy ' Create a new document If m_pres Is Nothing Then _ Set m_pres = m_ppt.Presentations.Add ' Paste the range into the PowerPoint document. Set sld = m_pres.Slides.Add(1, ppLayoutClipartAndText) ' Add a title. Set sh = sld.Shapes(1) sh.TextFrame.TextRange.Text = ActiveSheet.Name ' Paste the range. Set sh = sld.Shapes(3) sh.TextFrame.TextRange.Paste ' Replace second shape with a logo. Set sh = sld.Shapes(2) sld.Shapes.AddPicture ThisWorkbook.path & "\logo.bmp", _ False, True, sh.Left, sh.Top sh.Delete End If End Sub Sub ClosePPT( ) ' Step 5: Close PowerPoint. If Not (m_ppt Is Nothing) Then m_ppt.Quit ' Set the variable to Nothing. Set m_ppt = Nothing End Sub Private Sub m_ppt_NewPresentation(ByVal ...
Read now
Unlock full access