You use slide presentations to communicate information to an audience, and PowerPoint presentations are especially effective because they organize information in screen-size segments that audiences can absorb quickly. When you add the Excel chart to the presentation, you convey data results in an easy-to-understand format.
Sub CreatePowerPointPres() Dim appPPT As New PowerPoint.Application Dim presEnergy As PowerPoint.Presentation Dim sldUsage As PowerPoint.Slide Dim sgBottom As Single End Sub |
The first declaration defines the variable appPPT as a new instance of the PowerPoint Application object. The use of the keyword New in the declaration statement indicates that the first time you use the variable appPPT in code, you create a new instance. The second and third declarations define a Presentation object and a Slide object, respectively. The final declaration in the CreatePowerPointPres procedure defines the variable sgBottom as a Single data type, which is set to the bottom coordinate of the first slide's title shape.
Set presEnergy = appPPT.Presentations.Add Set sldUsage = presEnergy.Slides.Add(1, ppLayoutTitleOnly) With sldUsage.Shapes.Placeholders(1) With .TextFrame.TextRange .Text = "Energy Usage - " & g_sCircuit .Font.Bold = True .ChangeCase ppCaseUpper End With sgBottom = .Top + .Height End With |
You add the new presentation to the PowerPoint Application object in the first Set statement, and you add a new slide to the new presentation in the second Set statement. The new slide has the Title Only layout, which contains only a Title placeholder and no other preset shapes. The With…End block following the two Set statements accesses the properties of the Title placeholder to set the text, make the font bold, and change the case to uppercase. The last line in the With…End block sets the variable sgBottom to the sum of the top coordinate of the Title placeholder plus its height.
g_chtUsage.ChartArea.Copy With sldUsage.Shapes.Paste .Top = sgBottom + 20 .Height = sldUsage.Master.Height - sgBottom + 20 .Left = sldUsage.Master.Width / 2 - .Width / 2 End With |
In order to add the Excel chart to the PowerPoint presentation, you copy the chart area to the Clipboard and paste it into the Shapes collection of the first slide in the presentation. The With…End block then sets the top and left coordinates and the height of the newly pasted chart shape.
presEnergy.SaveAs g_sDBProjectPath & "EnergyPres" appPPT.Visible = True |
You've now added all the code needed to create a PowerPoint presentation.
Sub TestCreatingPowerPointPresentation() g_sDBProjectPath = Application.CurrentProject.Path & "\" modExcel.CreateExcelSheet GetDatabaseInfo bReport:=False, bSheet:=False, _ bPres:=True, bUpdateForm:=False modExcel.CreateChart modPowerPoint.CreatePowerPointPres End Sub |
Note the values of the arguments passed to the GetDatabaseInfo procedure. You set the first argument, bReport, to False because a report created in Word is not required. You set the second argument, bSheet, also to False. However, because you set the third argument, bPres, to True, an Excel spreadsheet and chart are created in order to copy the chart to the presentation created in PowerPoint. You set the last argument, bUpdateForm, to False because the Access form is not displayed.
When you run the procedure above, the slide should appear as follows: