We can systematize the tasks we do for PowerPoint using VBA. VBA’s ability to make references to other Microsoft products like “Microsoft Word” and “Microsoft PowerPoint” is one of its best features. Typically, Excel reports are produced first, followed by PowerPoint slides. In this article, we will demonstrate the instructions to open an existing PowerPoint file from excel VBA.
Download Practice Workbook
You can download the workbook and practice with them.
Step-by-Step Procedures to Open Existing PowerPoint File from Excel VBA
The Visual Basic for Applications (VBA) editor in Excel is an extremely effective tool. It enables you to create and change unique Excel automation scripts. We can write code as per our needs. With Excel VBA, users can easily use the code which acts as an excel menu from the ribbon. Suppose, we have a blank PPT file saved on Drive (D:). To use the VBA code to open an existing PowerPoint file, let’s follow the steps down.
Step 1: Launch Developer Tab
First, we need to Launch the developer tab on excel. To enable this feature we need to follow the following steps.
- To begin with, right-click on the ribbon.
- Then, select Customize the Ribbon.
- Thus, the Excel Options dialog box will appear.
- Further, go to Customize Ribbon.
- Checkmark the Developer tab under Main Tabs.
- Finally, click on the OK button.
- Thus, the Developer tab will appear in the ribbon.
Step 2: Create CommandButton
A macro or process can be run or executed using the CommandButton. Whenever a user clicks on a command button, it executes a task or operation. The Spreadsheet supports the usage of the Command Button.
- Go to the Developer tab from the ribbon.
- Further, click on the Insert drop-down menu, under the Controls group.
- Then, select CommandButton from ActiveX Controls.
- Drag your mouse and place the button as you want it and click on it.
- This will automatically take you to the Visual Basic Editor.
Step 3: Enable PowerPoint Object Model
At this step, we need to go through PowerPoint’s security settings and activate all Macros before you can utilize VBA code or snippets to operate in PowerPoint. After that, we may utilize the MS PowerPoint VBA reference for Macros.
- Go to the Tools tab from the ribbon.
- Then, click on References.
- Thus, the References – VBAProject window will be displayed.
- Further, scroll down a bit and check mark Microsoft PowerPoint 16.0 Object Library.
- Lastly, clicking on the OK button will finish the step.
- How to Copy Chart from Excel to PowerPoint Without Link
- Link Powerpoint to Excel for Dynamic Data Updates
- How to Insert an Excel File into PowerPoint as an Icon
Step 4: Insert VBA Code
At this step, we will write our code in the Visual Basic Editor.
- Copy and paste the following VBA code shown below.
Private Sub CommandButton1_Click() Dim PwrApp As PowerPoint.Application Dim PwrPre As PowerPoint.Presentation Dim PwrSd As PowerPoint.Slide Set PwrApp = New PowerPoint.Application Set PwrPre = PwrApp.Presentations.Open("D:\Presentation1.pptx") End Sub
Step 5: Final Output
To see the final result after using the VBA code. Let’s do the following.
- Go back to your worksheet and click on CommandButton1.
- This will open the existing file.
How to Create PowerPoint File with Excel VBA
Now, we will demonstrate how to use VBA source code to construct a PowerPoint presentation from an Excel spreadsheet if you devote a lot of time creating Powerpoint slides.
- Firstly, go to the Developer tab from the ribbon.
- Secondly, click on Visual Basic from the Code category to open the Visual Basic Editor. Or press Alt + F11 to open the Visual Basic Editor.
- Instead of doing this, you can just right-click on your worksheet and go to View Code. This will also take you to Visual Basic Editor.
- This will appear in the Visual Basic Editor where we write our code.
- Thirdly, click on Module from the Insert drop-down menu bar.
- This will create a Module in your workbook.
- And, copy and paste the VBA code shown below.
Sub Create_PPT() Dim PwrApp As PowerPoint.Application Dim PwrPre As PowerPoint.Presentation Dim PwrSde As PowerPoint.Slide Dim PwrShpe As PowerPoint.Shape Dim PwrChrt As Excel.ChartObject Set PwrApp = New PowerPoint.Application PwrApp.Visible = msoCTrue PwrApp.WindowState = ppWindowMaximized Set PwrPre = PwrApp.Presentations.Add Set PwrSd = PwrPre.Slides.Add(1, ppLayoutTitleOnly) End Sub
- After that, run the code by clicking on the RubSub button or pressing the keyboard shortcut F5.
- This will create a PowerPoint slide.
The above procedures will assist you to Open Existing Powerpoint File from Excel VBA. Hope this will help you! Please let us know in the comment section if you have any questions, suggestions, or feedback. Or you can glance at our other articles in the ExcelDemy.com blog!