How to Open Existing PowerPoint File from Excel VBA

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.


How to Open Existing PowerPoint File from Excel VBA: Step-by-Step Procedures

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.

open existing powerpoint from excel vba


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.

open existing powerpoint from excel vba

  • 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.

open existing powerpoint from excel vba


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.

open existing powerpoint from excel vba


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.

VBA Code:

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

open existing powerpoint from excel vba

Note: You don’t need to change the code. All you can do is just change the file path as per your requirements.

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.

STEPS:

  • 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.

open existing powerpoint from excel vba

  • This will appear in the Visual Basic Editor where we write our code.
  • Thirdly, click on Module from the Insert drop-down menu bar.

open existing powerpoint from excel vba

  • This will create a Module in your workbook.
  • And, copy and paste the VBA code shown below.

VBA Code:

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.

open existing powerpoint from excel vba

  • This will create a PowerPoint slide.

Read More: [Solved] Embedded Excel in PowerPoint Not Showing All Data


Download Practice Workbook

You can download the workbook and practice with them.


Conclusion

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.


Related Articles

<< Go Back to Excel to PowerPoint | Export Data from Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Sabrina Ayon
Sabrina Ayon

Sabrina Ayon, a Computer Science and Engineering graduate from United International University, has been an integral part of the ExcelDemy project for two years. She authored 150+ articles, excelling in instructing through visually engaging Excel tutorials. With a passion for teaching, Sabrina conducted sessions on Excel VBA, sharing her knowledge and insights with others. Currently holding the position of Project Manager for the ExcelDemy Visual Development Project, she oversees various aspects of the project, ensuring its smooth operation... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo