powerpoint vba get current presentation

Contribute to the Microsoft 365 and Office forum! Click  here  to learn more  💡

April 9, 2024

Contribute to the Microsoft 365 and Office forum!

Click  here  to learn more  💡

PowerPoint Forum Top Contributors: Steve Rindsberg  -  John Korchok  -  Bob Jones AKA: CyberTaz   ✅

May 10, 2024

PowerPoint Forum Top Contributors:

Steve Rindsberg  -  John Korchok  -  Bob Jones AKA: CyberTaz   ✅

  • Search the community and support articles
  • Microsoft 365 and Office
  • Search Community member

Ask a new question

Bob Umlas, Excel MVP

In PowerPoint VBA, how do I refer to the ACTIVE slide?

I want to be able to insert an object on the active slide in VBA code. I could only find

ActivePresentation.Slides(2).Shapes.Addshape...

like I have to refer to a particular slide rather than the active one. I'm sure it can be done, but couldn't find it by browsing the object browser.

Report abuse

Reported content has been submitted​

HansV MVP

Use code like this:

Dim sld As Slide Dim shp As Shape Set sld = Application.ActiveWindow.View.Slide Set shp = sld.Shapes.AddShape(Type:=msoShapeRectangle, _     Left:=50, Top:=50, Width:=100, Height:=200) shp.Fill.ForeColor.RGB = vbBlue

47 people found this reply helpful

Was this reply helpful? Yes No

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

Thanks for your feedback.

Replies (13) 

Question info.

  • Norsk Bokmål
  • Ελληνικά
  • Русский
  • עברית
  • العربية
  • ไทย
  • 한국어
  • 中文(简体)
  • 中文(繁體)
  • 日本語

Determine The Current ActiveShape In PowerPoint With VBA

Determine The Current ActiveShape In Microsoft PowerPoint With VBA

What This VBA Code Does

This code will set a variable named ActiveShape to equal the shape that is currently selected by the user.  If multiple shapes are selected, the code will default the variable to equal the shape that was clicked on first.  I use this methodology often while writing macros to analyze characteristics of a shape within my PowerPoint slide.

Using VBA Code Found On The Internet

Now that you’ve found some VBA code that could potentially solve your Excel automation problem, what do you do with it? If you don’t necessarily want to learn how to code VBA and are just looking for the fastest way to implement this code into your spreadsheet, I wrote an article (with video) that explains how to get the VBA code you’ve found running on your spreadsheet.

Getting Started Automating Excel

Are you new to VBA and not sure where to begin? Check out my quickstart guide to learning VBA . This article won’t overwhelm you with fancy coding jargon, as it provides you with a simplistic and straightforward approach to the basic things I wish I knew when trying to teach myself how to automate tasks in Excel with VBA Macros.

Also, if you haven’t checked out Excel’s latest automation feature called Power Query , I have put together a beginner’s guide for automating with Excel’s Power Query feature as well! This little-known built-in Excel feature allows you to merge and clean data automatically with little to no coding!

How Do I Modify This To Fit My Specific Needs?

Chances are this post did not give you the exact answer you were looking for. We all have different situations and it's impossible to account for every particular need one might have. That's why I want to share with you:  My Guide to Getting the Solution to your Problems FAST!  In this article, I explain the best strategies I have come up with over the years to get quick answers to complex problems in Excel, PowerPoint, VBA,  you name it ! 

I highly recommend that you check this guide  out before asking me or anyone else in the comments section to solve your specific problem. I can guarantee that 9 times out of 10, one of my strategies will get you the answer(s) you are needing faster than it will take me to get back to you with a possible solution. I try my best to help everyone out, but sometimes I don't have time to fit everyone's questions in (there never seem to be quite enough hours in the day!).

I wish you the best of luck and I hope this tutorial gets you heading in the right direction!

After 10+ years of creating macros and developing add-ins, I've compiled all the hacks I wish I had known years ago!

Hidden Hacks For VBA Macro Coding

Keep Learning

Loop Through Each Slide In Your Active PowerPoint Presentation

Loop Through Each Slide In Your Active PowerPoint Presentation

What This VBA Code Does Often times we want to make changes that affect every slide in the PowerPoint presentation....

PowerPoint VBA Function To Test If Object Can Contain Text

PowerPoint VBA Function To Test If Object Can Contain Text

What This VBA Code Does In PowerPoint, it can be very useful to know if the object you are working...

Retrieve The Dimensions Of A Shape In PowerPoint

Retrieve The Dimensions Of A Shape In PowerPoint

What This VBA Code Does: The VBA code below displays a message box with a selected PowerPoint item's Left, Top,...

Chris Newman

Chris Newman

Chris is a finance professional and Excel MVP recognized by Microsoft since 2016. With his expertise, he founded TheSpreadsheetGuru blog to help fellow Excel users, where he shares his vast creative solutions & expertise. In addition, he has developed over 7 widely-used Excel Add-ins that have been embraced by individuals and companies worldwide.

Excel Off The Grid

Powerpoint VBA Reference Library

The code below is intended to be a basic reference to anybody trying to use VBA code for Powerpoint.  It’s certainly not complete, but it is code I’ve used for various reasons.  I will try to add to and improve this reference as I use more PowerPoint VBA code.

Referencing presentations, slides and shapes

Count the number of slides, get the slide index number of the current slide.

ppLayoutBlank is just one of a number of available layout options.

Delete Slides

 move slides, looping through all the slides of the active presentation, looping through all the shapes on the active slide, looping through all shapes on all slides, looping through all linked shapes on all slides.

If you are applying a method, the other option is to apply the method to all shapes, even if they are not linked. You will need to handle the errors where that shape is not a linked shape.

Managing Links

Some of the methods related to links occur at the presentation level, whilst others occur at the shape level.

Presentation level methods

Shape level methods.

The code snippets in this section do not stand alone.  They must be used where the pptShape has been set or defined through a loop.

Discover how you can automate your work with our Excel courses and tools.

Excel Academy

Excel Academy The complete program for saving time by automating Excel.

Excel Automation Secrets

Excel Automation Secrets Discover the 7-step framework for automating Excel.

Office Scripts Course

Office Scripts: Automate Excel Everywhere Start using Office Scripts and Power Automate to automate Excel in new ways.

2 thoughts on “Powerpoint VBA Reference Library”

Hi, I found this nice page on PowerPoint snippets, but could not find the VBA code to get a reference to an existing instance of PPT. It’s called CreateOrGetObject or GetOrCreateObject or something like that. If you ever update this page, that would be a useful snippet to include. I bookmarked this page in case I need some of these snippets one day. Thank you!

Thanks Kevin, that’s good feedback. I’ll add that in the next time I update it 🙂

Leave a Comment Cancel reply

Excel Any Time

Automate Microsoft PowerPoint from Excel, using vba, Run a Slide Show Automate Microsoft PowerPoint from Excel, using vba, Run a Slide Show

Automate Microsoft PowerPoint from Excel, using vba, Run a Slide Show

VBA TUTORIAL LOGIN

Cond statements in vba test.

  • If…Then…Else Statements
  • Select…Case Statements

Text Strings in VBA

  • VBA String Functions – Left, Right, Mid, Len, Replace, InStr & InStrRev
  • VBA String Functions – Split, Join, Concatenate

Custom Number Formats

  • Custom Number Formats in VBA
  • Excel VBA Built-in Events
  • Worksheet Change Event
  • Worksheet Selection Change Event

ActiveX & Form Controls

  • ActiveX & Form Controls, AutoShapes

Application.OnTime Method

  • Application.OnTime – Schedule Macros
  • MsgBox & InputBox in VBA
  • Ebook of Excel Formulas
  • Split Values into Multiple Equal Groups
  • Count number of Cells containing Specific Letter(s)
  • Assign separate Values to Non-Contiguous Cells and return SUM
  • Average of first 10 values in a column, Ignore Error Values
  • Count Unique Values in Excel
  • Countif with Array Criteria, using AND / OR criteria
  • SUM Largest 4 Values in Non-Contiguous Cells of a Row
  • Average of Last 20 Positive values only in a Column
  • Count Unique values in a Column, with Conditions
  • Excel Text and String Functions: TRIM & CLEAN
  • ASCII Code, Extended ASCII characters (8-bit system) and ANSI Code.
  • Excel CODE & CHAR Functions, VBA Asc & Chr Functions
  • Excel Text and String Functions: LEFT, RIGHT, MID, LEN, FIND, SEARCH, REPLACE, SUBSTITUTE
  • CHOOSE Function in Excel
  • Excel IF Function and IF Statements
  • Excel VLOOKUP Function
  • Excel OFFSET Function
  • Excel INDIRECT Function
  • Excel SUMPRODUCT Function
  • Printing a Pivot Table Report – Excel
  • Create a Pivot Chart in Excel – graphical display of a Pivot Table
  • Excel Pivot Table Design & Layout, Pivot Table Styles
  • Excel Pivot Table Report – Sort Data in Row & Column Labels & in Values Area, use Custom Lists
  • Excel Pivot Tables: Filter Data, Items, Values & Dates
  • Excel Pivot Tables: Insert Calculated Fields & Calculated Items, Create Formulas
  • Excel Pivot Table Report – Summary Functions & Custom Calculations, Insert Calculated Fields or Calculated Items
  • Excel Pivot Table Report – Group Items, Group Date and Time Values
  • Excel Pivot Table Report – Field Settings, Expand or Collapse Fields & Items, Refresh Data, Change Data Source & Show or Hide options
  • Excel Pivot Table Report – Clear All, Remove Filters, Select Mutliple Cells or Items, Move a Pivot Table
  • Case Sensitive Vlookup in Excel; Finding the 1st, 2nd, nth or last occurrence of the Lookup Value
  • Vlookup Multiple Values – Return MULTIPLE corresponding values for ONE Lookup Value
  • Excel Date and Time Functions and Formulas
  • Find ‘Smallest’, ‘Largest’, ‘K-th Smallest’ and ‘K-th Largest’ Numbers in a Range
  • Remove Duplicates in a range, using “Remove duplicates” button in Data Tools
  • Remove Duplicates or Create a List of Unique Records using Excel Formula
  • Remove Duplicates or Create a List of Unique Records using Advanced Data Filter
  • Count Number of Unique Values in a Range (with Excel Functions)
  • Shade Alternate Rows – Conditional Formatting
  • Left Lookup with Vlookup Excel Function
  • Excel VBA: ActiveX Controls, Form Controls & AutoShapes on a Worksheet
  • ChartFormat object – line, fill & effect formatting for chart elements: FillFormat object, LineFormat object, ShadowFormat object, GlowFormat object, SoftEdgeFormat object, ThreeDFormat object
  • Child Objects common for many chart elements: Border Object, ChartFillFormat Object, Interior Object, Font Object
  • Chart Elements in Excel VBA (Part 2) – Chart Series, Data Labels, Chart Legend
  • Chart Elements in Excel VBA (Part 1) – Chart Title, Chart Area, Plot Area, Chart Axes
  • Charts in Excel VBA – Add a Chart, the Chart object & the ChartObject object
  • Create Charts in Excel VBA: Embedded Charts – Line with Markers; Clustered Stacked Column Chart; Clustered Stacked Bar Chart displaying Variance; Pie chart; XY Scatter chart & Bubble chart
  • Excel VBA Debugging Tools in Visual Basic Editor – Breakpoints & Break Mode, Stepping Through Code, Debugging Views
  • Excel VBA Errors & Error Handling, On Error & Resume Satements, Exit Statement, Err Object
  • Excel VBA Date & Time Functions; Year, Month, Week & Day Functions
  • Website Use Policy
  • Excel VBA Online Tutorial
  • Testimonials GlobaliConnect.com
  • About ExcelAnytime.com
  • Excel VBA Online Tutorial – learn Excel VBA programming & access examples, illustrations, live codes and downloadable files
  • Excel and VBA Services
  • Who’s Online
  • Using Joomla!
  • Australian Parks
  • Latest Users Module
  • Cradle Mountain
  • Administrator Components
  • Happy Orange Orchard
  • Wonderful Watermelon
  • Article Categories Module
  • Search Module
  • Articles Category Module
  • Statistics Module
  • Latest Articles Module
  • Syndicate Module
  • Feed Display
  • Footer Module
  • Random Image Module
  • Weblinks Module
  • Archive Module
  • Language Switcher
  • Custom HTML Module
  • Most Read Content
  • Related Items Module
  • Banner Module
  • Menu Module
  • Breadcrumbs Module
  • Login Module
  • Wrapper Module
  • Authentication
  • Editors-xtd
  • First Blog Post
  • Second Blog Post
  • Phyllopteryx
  • Spotted Quoll
  • Blue Mountain Rain Forest
  • Ormiston Pound
  • VBATutorial - Cond Stmnts

—————————————————————————————————————

Automate Microsoft PowerPoint from Excel

Create a new PowerPoint ppt of 3 slides with sound effect, and run a slide show, using Early Binding

Create a new PowerPoint ppt of 4 slides with sound clips and chart, run & view the slide show, automatically close & quit the PowerPoint application, using Early Binding

Create a new PowerPoint ppt of 4 slides with sound effects and chart, run & view the slide show, automatically close & quit the PowerPoint application, using Late Binding

In this section it is explained how to create, open, insert slide / shape / text and save and close a new PowerPoint ppt, using Automation in vba. Examples have been given to automate using both Early Binding and Late Binding.

When you use vba in an Office Application, say PowerPoint, a reference to the PowerPoint Object Library is set by default. When you Automate to work with PowerPoint objects from another application, say Excel, you can add a reference to the PowerPoint object library in Excel (your host application) by clicking Tools-References in VBE, which will enable using PowerPoint’s predefined constants. This is a must when you automate using Early Binding (explained earlier) . Once this reference is added, a new instance of PowerPoint application can be created by using the New keyword.

Automate PowerPoint from Excel, using Late Binding: You need not add a reference to the PowerPoint object library in Excel (your host application), in this case you will not be able to use the PowerPoint’s predefined constants and will need to replace them by their numerical values in your code. In Late Binding, the object variable is declared as an Object Type which can be a reference to any object, and this makes an object late bound. In Late Binding, the object library is not exposed during design-time, but the binding happens during run-time using the CreateObject or the GetObject functions. CreateObject creates a new instance of Outlook and GetObject returns an already running instance of the PowerPoint object.

Click here for a detailed explanation of Automation using Early Binding and Late Binding.

Scroll down to Example 3 to download an Excel file, for live code of a 4-slide PowerPoint Presentation which Runs an automated Slide Show.

Example 1: Create a new PowerPoint ppt of 3 slides with sound effect, and run a slide show, using Early Binding.

Sub Automating_PowerPoint_from_Excel_1() ‘Automate using Early Binding: Add a reference to the PowerPoint Object Library in Excel (your host application) by clicking Tools-References in VBE, which will enable using PowerPoint’s predefined constants. Once this reference is added, a new instance of PowerPoint application can be created by using the New keyword .

‘Create a new PowerPoint ppt of 3 slides with sound effect, and run a slide show.

‘variables declared as a specific object type ie. specific to the application which is being automated: Dim applPP As PowerPoint.Application Dim prsntPP As PowerPoint.Presentation Dim slidePP As PowerPoint.Slide Dim shapePP As PowerPoint.Shape Dim lSlideCount As Long Dim strPpPath As String, strPpName As String

‘Create a new instance of the PowerPoint application. Set the Application object as follows: Set applPP = New PowerPoint.Application

‘make the PowerPoint window visible: applPP.Visible = True ‘maximize PowerPoint window: applPP.WindowState = ppWindowMaximized

‘create a new presentation in PowerPoint: Set prsntPP = applPP.Presentations.Add

‘set path where to save the new presentation, to the same location as the host workbook: strPpPath = ThisWorkbook.Path ‘set name for the new presentation with the defined path as determined above: strPpName = strPpPath & “\” & “newPresentation1.pptx”

‘saves the new presentation, with the specified name and path: prsntPP.SaveAs Filename:=strPpName

‘use the SlideMaster Property to set the background for all slides: prsntPP.SlideMaster.Background.Fill.PresetTextured msoTextureStationery

‘————————- ‘ADD FIRST SLIDE: ‘The title slide (ppLayoutTitleOnly) has 1 shape, Shape(1) is the title, you can add your own shapes to the slide: ‘add a title slide to the new presentation : Set slidePP = prsntPP.Slides.Add(Index:=1, Layout:=ppLayoutTitleOnly)

‘use the SlideShowTransition Property to determine how the slide advances in a slide show:

With slidePP.SlideShowTransition

.Speed = ppTransitionSpeedFast .EntryEffect = ppEffectWedge ‘set AdvanceOnTime property to true for the slide to advance automatically after the specified time gap: .AdvanceOnTime = msoTrue ‘AdvanceTime Property sets the time gap in seconds for the specified slide transition. ‘set the slide advance time of 20 seconds before it advances to the next slide:

.AdvanceTime = 17

‘REFER FIRST SHAPE IN FIRST SLIDE: ‘Text Frame refers to the area within a shape that holds text and it has properties and methods to control its alignment and anchoring. ‘TextRange refers to text in a shape and it has properties and methods to add and manipulate text. ‘set the title text on the slide: slidePP.Shapes.Title.TextFrame.TextRange.Text = “Sales Performance – 2012”

‘ADD SECOND SHAPE IN FIRST SLIDE: ‘create a new shape in the slide: Set shapePP = slidePP.Shapes.

AddShape(Type:=msoShapeOval, Left:=50, Top:=150, Width:=120, Height:=90)

With shapePP

.Fill.ForeColor.RGB = RGB(255, 0, 0) .TextFrame.TextRange.Text = “Presented by Scott Kelly” .TextFrame.TextRange.Font.Name = “Arial” .TextFrame.TextRange.Font.Size = 12 .TextEffect.FontBold = msoTrue

‘use the Shape.AnimationSettings Property to apply special effects for animation of a shape during a slide show:

With .AnimationSettings

.SoundEffect.Name = “Camera” .AdvanceMode = ppAdvanceOnTime .AdvanceTime = 2 .EntryEffect = ppEffectFlyFromLeft ‘use TextUnitEffect Property to determine how the text is animated – by paragraph, by word, or by letter:

.TextUnitEffect = ppAnimateByParagraph

‘ADD THIRD SHAPE IN FIRST SLIDE: ‘create a new shape in the slide: Set shapePP = slidePP.

Shapes.AddShape(Type:=msoShape8pointStar, Left:=220, Top:=200, Width:=250, Height:=270)  

‘set the shape properties:

.Name = “Company” .Fill.ForeColor.RGB = RGB(0, 255, 0) .Fill.OneColorGradient msoGradientHorizontal, 4, 0.2 .Line.Style = msoLineSingle

‘note that vbCrLf or Chr(13) have the effect of creating a new paragraph: .TextFrame.TextRange.Text = “Company Name: CarSalesCo Inc, USA” & vbCrLf & vbCrLf & “Includes” & vbCrLf & “all Branches Worldwide”

.TextFrame.TextRange.Font.Name = “Arial” .TextFrame.TextRange.Font.Size = 18

.TextEffect.FontBold = msoTrue

‘Set the AnimationSettings.AdvanceMode Property to ppAdvanceOnTime, for the animation to start automatically after the specified time gap. .AdvanceMode = ppAdvanceOnTime ‘animate specified shape automatically after 2 seconds: .AdvanceTime = 2 .SoundEffect.Name = “Camera” .EntryEffect = ppEffectFlyFromLeft ‘The AnimationSettings.TextLevelEffect Property determines the paragraph level by which the text in a shape gets animated: .TextLevelEffect = ppAnimateBySecondLevel

.TextUnitEffect = ppAnimateByCharacter

‘————————- ‘ADD SECOND SLIDE: lSlideCount = prsntPP.Slides.Count

‘The text slide (ppLayoutText)has 2 shapes wherein text can be inserted, Shape(1) is the title, and Shape(2) is the bulleted text area: Set slidePP = prsntPP.Slides.Add(Index:=lSlideCount + 1, Layout:=ppLayoutText)

.Speed = ppTransitionSpeedSlow .EntryEffect = ppEffectFadeSmoothly .AdvanceOnTime = msoTrue

.AdvanceTime = 12

‘REFER THE FIRST SHAPE IN SECOND SLIDE :

With slidePP.Shapes(1)

.TextFrame.TextRange.Text = “Your Company has returned a Bumper Sales Performance during the Financial Year 2012. Highlights:”

.TextFrame.TextRange.Font.Name = “Verdana” .TextFrame.TextRange.Font.Color = RGB(255, 0, 0) .TextFrame.TextRange.Font.Size = 20

.SoundEffect.Name = “Camera” .AdvanceMode = ppAdvanceOnTime .AdvanceTime = 2 .TextUnitEffect = ppAnimateByParagraph

.EntryEffect = ppEffectFlyFromRight

‘REFER THE SECOND SHAPE IN SECOND SLIDE:

With slidePP.Shapes(2)

‘use the TextRange.ParagraphFormat Property to do paragraph formatting for the specified text.

With .TextFrame.TextRange.ParagraphFormat

‘set paragraph alignment: .Alignment = ppAlignJustify ‘msoTrue indicates that line spacing is set to a specific number of lines between base lines whereas msoFalse indicates that line spacing is set to a specific number of points: .LineRuleWithin = msoTrue ‘set space between base lines: .SpaceWithin = 1.2 ‘msoTrue indicates that line spacing is set to a specific number of lines before each paragraph’s first line whereas msoFalse indicates that line spacing is set to a specific number of points. .LineRuleBefore = msoTrue ‘set the space after before each paragraph’s first line: .SpaceBefore = 0.5 ‘msoTrue indicates that line spacing is set to a specific number of lines after each paragraph’s last line whereas msoFalse indicates that line spacing is set to a specific number of points. .LineRuleAfter = msoTrue ‘set the space after after each paragraph’s last line:

.SpaceAfter = 0.75

‘this shape is the bulleted text area, here we are changing the bullet type: .TextFrame.TextRange.

ParagraphFormat.Bullet.Type = ppBulletNumbered

.TextFrame.TextRange.Text = “All Sales Targets have been Exceeded and this is due to the tremendous efforts of the staff and management led by the Managing Director, Mr. Kurt Murray” & Chr(13) & “200% Sales Growth over the Previous Year” & Chr(13) & “250% Increase in Net Profit” & Chr(13) & “Best Sales Performance Region – North America” & Chr(13) & “Record Sales in the Month of June” & Chr(13) & “Best Individual Target Achievment – Mr. Jim Holland”

.TextFrame.TextRange.Font.Name = “Times New Roman” .TextFrame.TextRange.Font.Size = 18 .TextEffect.FontBold = msoTrue

.AdvanceMode = ppAdvanceOnTime .AdvanceTime = 2 .SoundEffect.Name = “Camera” .TextUnitEffect = ppAnimateByParagraph

‘————————- ‘ADD THIRD SLIDE: lSlideCount = prsntPP.Slides.Count

‘Being a blank slide (ppLayoutBlank), it has no shapes, you can add your shapes to the slide: Set slidePP = prsntPP.Slides.Add(Index:=lSlideCount + 1, Layout:=ppLayoutBlank)

‘You use the SlideMaster Property to set the background gradient for all slides, as shown in the beginning. If you want to set the background for an individual slide without affecting other slides, you need to set the FollowMasterBackground property of a slide to False, as shown below. slidePP.FollowMasterBackground = False slidePP.Background.Fill.PresetGradient Style:=msoGradientHorizontal, Variant:=1, PresetGradientType:=msoGradientDesert

.Speed = ppTransitionSpeedSlow .EntryEffect = ppEffectBoxOut .AdvanceOnTime = msoTrue

.AdvanceTime = 10

‘create a new shape in the slide: Set shapePP = slidePP.Shapes.AddShape(Type:=

msoShapeRectangle, Left:=10, Top:=10, Width:=470, Height:=250)

‘activate the new slide: applPP.ActiveWindow.View.GotoSlide prsntPP.Slides.Count ‘select shape to align: shapePP.Select ‘aligning a shape(s): ‘ShapeRange object represents all slide objects selected in the slide. Align (ie. ShapeRange.Align Method) works with ShapeRange, and not with a Shape, hence selection of a shape is required to use the Selection.ShapeRange Property as below. applPP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, msoTrue applPP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, msoTrue

‘Aligns all shapes in the slide: ‘slidePP.Shapes.Range.Align msoAlignCenters, msoTrue

‘vertical alignment of textframe in the selected shape: applPP.ActiveWindow.Selection.ShapeRange.

TextFrame2.VerticalAnchor = msoAnchorTop

‘REFER THE FIRST SHAPE IN THIRD SLIDE:

.Fill.ForeColor.RGB = RGB(255, 100, 100)

‘Chr(32) adds a space; Chr(13) is carriage return and has the effect of creating a new paragraph: .TextFrame.TextRange.Text = Chr(32) & “We hope to Continue this Strong Performance” & Chr(13) & Chr(13) & Chr(32) & “Thank You Ladies & Gentlemen” & Chr(13) & Chr(13) & Chr(32) & “End of Presentation”

.TextFrame.TextRange.ParagraphFormat.

Alignment = ppAlignJustify ‘add bullets to all text in the range: .TextFrame.TextRange.ParagraphFormat.

Bullet.Type = ppBulletUnnumbered ‘to add bullets to the first paragraph: ‘.TextFrame.TextRange.Paragraphs(1).

ParagraphFormat.Bullet.Type = ppBulletUnnumbered ‘to add bullets to the last paragraph: ‘.TextFrame.TextRange.

Paragraphs(.TextFrame.TextRange.Paragraphs.

Count).ParagraphFormat.Bullet.Character = 8226 ‘indent last para: .TextFrame.TextRange.Paragraphs(3).

IndentLevel = 2 .TextFrame.TextRange.

Paragraphs(.TextFrame.

TextRange.Paragraphs.Count).IndentLevel = 3 .TextFrame.TextRange.Font.Name = “Times New Roman” .TextFrame.TextRange.Font.Size = 20

.AdvanceMode = ppAdvanceOnTime .AdvanceTime = 2 ‘You can assign different sound effects for each shape viz. Chime, Applause, etc. Play the powerpoint sound named Applause: .SoundEffect.Name = “Chime” .TextUnitEffect = ppAnimateByParagraph

.EntryEffect = ppEffectCheckerboardAcross

‘————————- ‘FONT SETTINGS IN FIRST SLIDE:

‘refer shape by its name: prsntPP.Slides(1).Shapes(“Company”).TextFrame.

TextRange.Paragraphs(1).Lines(1).Font.Italic = True ‘format as italic the second and third lines of the first paragraph in shape three on slide one in the current powerpoint presentation: prsntPP.Slides(1).Shapes(3).TextFrame.

TextRange.Paragraphs(1).Lines(2, 3).Font.Color = vbBlue prsntPP.Slides(1).Shapes(3).TextFrame.

TextRange.Paragraphs(3).Lines(1).Font.Underline = True

‘————————- ‘SAVE PRESENTATION, AND RUN THE SLIDE SHOW:

‘save the presentation: prsntPP.Save

‘minimize Excel window: Application.WindowState = xlMinimized

lSlideCount = prsntPP.Slides.Count ‘run the slide show: applPP.ActiveWindow.View.GotoSlide 1

‘use the SlideShowSettings Property to set the slide show settings of the presentation:

With prsntPP.SlideShowSettings

.StartingSlide = 1 .EndingSlide = lSlideCount ‘slides will advance per the timings (ie. SlideShowTransition.AdvanceTime) set therein: .AdvanceMode = ppSlideShowUseSlideTimings

Example 2: Create a new PowerPoint ppt of 4 slides with sound clips and chart, run & view the slide show, automatically close & quit the PowerPoint application, using Early Binding.

Sub Automating_PowerPoint_from_Excel_2() ‘Automate using Early Binding: Add a reference to the PowerPoint Object Library in Excel (your host application) by clicking Tools-References in VBE, which will enable using PowerPoint’s predefined constants. Once this reference is added, a new instance of PowerPoint application can be created by using the New keyword .

‘Create a new PowerPoint ppt of 4 slides with sound clips and chart, run & view the slide show, automatically close & quit the PowerPoint application.

‘variables declared as a specific object type ie. specific to the application which is being automated: Dim applPP As PowerPoint.Application Dim prsntPP As PowerPoint.Presentation Dim slidePP As PowerPoint.Slide Dim shapePP As PowerPoint.Shape Dim shapeSoundPP As PowerPoint.Shape Dim lSlideCount As Long Dim oSlideShowPP As Object Dim strPpPath As String, strPpName As String

‘create a new presentation in PowerPoint: Set prsntPP = applPP.Presentations.Add ‘set path where to save the new presentation, to the same location as the host workbook: strPpPath = ThisWorkbook.Path ‘set name for the new presentation with the defined path as determined above: strPpName = strPpPath & “\” & “newPresentation1.pptx”

‘use the SlideMaster Property to set the background gradient for all slides: prsntPP.SlideMaster.Background.Fill.

PresetGradient Style:=msoGradientHorizontal, Variant:=1, PresetGradientType:=msoGradientDaybreak

‘————————- ‘ADD FIRST SLIDE: ‘The title slide (ppLayoutTitleOnly) has 1 shape, Shape(1) is the title, you can add your own shapes to the slide: ‘add a title slide to the new presentation: Set slidePP = prsntPP.Slides.Add(Index:=1, Layout:=ppLayoutTitleOnly)

‘ADD SECOND SHAPE IN FIRST SLIDE (MEDIA OBJECT): ‘Add sound in your slide – use the Shapes.AddMediaObject Method to create a media object: Set shapeSoundPP = slidePP.Shapes.AddMediaObject(“C:\Users\Amit Tandon\Documents\Sound\10 S.O.S..m4a”, Left:=5, Top:=5, Width:=10, Height:=10)

‘use AnimationSettings.PlaySettings Property to set how the sound clip plays during the slide show:

With shapeSoundPP.AnimationSettings.PlaySettings

‘play sound automatically after the slide transition: .PlayOnEntry = True ‘Determine whether to pause the slide show till the finish of the sound clip: .PauseAnimation = False ‘two slides will be displayed before the sound clip stops playing:

.StopAfterSlides = 2

.AdvanceTime = 20

‘ADD THIRD SHAPE IN FIRST SLIDE: ‘create a new shape in the slide: Set shapePP = slidePP.Shapes.AddShape(Type:=msoShapeOval, Left:=50, Top:=150, Width:=120, Height:=90)

.Fill.ForeColor.RGB = RGB(255, 0, 0) .TextFrame.TextRange.Text = “Presented by Scott Kelly” .TextFrame.TextRange.Font.Name = “Arial” .TextFrame.TextRange.Font.Size = 12

.AdvanceMode = ppAdvanceOnTime .AdvanceTime = 2 .EntryEffect = ppEffectFlyFromLeft ‘use TextUnitEffect Property to determine how the text is animated – by paragraph, by word, or by letter:

.TextUnitEffect = ppAnimateByWord

‘ADD FOURTH SHAPE IN FIRST SLIDE: ‘create a new shape in the slide: Set shapePP = slidePP.Shapes.AddShape(Type:=

msoShape8pointStar, Left:=220, Top:=200, Width:=250, Height:=270)  

.Name = “Company” .Fill.ForeColor.RGB = RGB(0, 255, 0) .Line.Style = msoLineThickThin

‘Set the AnimationSettings.AdvanceMode Property to ppAdvanceOnTime, for the animation to start automatically after the specified time gap. .AdvanceMode = ppAdvanceOnTime ‘animate specified shape automatically after 2 seconds: .AdvanceTime = 2 .EntryEffect = ppEffectFlyFromLeft ‘The AnimationSettings.TextLevelEffect Property determines the paragraph level by which the text in a shape gets animated: .TextLevelEffect = ppAnimateBySecondLevel

.Speed = ppTransitionSpeedSlow .EntryEffect = ppEffectUncoverDown .AdvanceOnTime = msoTrue

‘REFER THE FIRST SHAPE IN SECOND SLIDE:

.TextFrame.TextRange.Font.Name = “Verdana” .TextFrame.TextRange.Font.Color = RGB(0, 255, 0) .TextFrame.TextRange.Font.Size = 20

.AdvanceMode = ppAdvanceOnTime .TextUnitEffect = ppAnimateByParagraph

‘use the TextRange.ParagraphFormat Property to do paragraph formatting for the specified text. ‘this shape is the bulleted text area, here we are changing the bullet type: .TextFrame.TextRange.ParagraphFormat.

Bullet.Type = ppBulletNumbered .TextFrame.TextRange.Text = “All Sales Targets have been Exceeded” & Chr(13) & Chr(13) & “200% Sales Growth over the Previous Year” & Chr(13) & Chr(13) & “250% Increase in Net Profit” & Chr(13) & Chr(13) & “Best Sales Performance Region – North America” & Chr(13) & Chr(13) & “Record Sales in the Month of June” & Chr(13) & Chr(13) & “Best Individual Target Achievment – Mr. Jim Holland” .TextFrame.TextRange.Font.Name = “Times New Roman” .TextFrame.TextRange.Font.Size = 18 .TextEffect.FontBold = msoTrue

.AdvanceMode = ppAdvanceOnTime .AdvanceTime = 1 .TextUnitEffect = ppAnimateByParagraph .TextLevelEffect = ppAnimateBySecondLevel

‘————————- ‘ADD THIRD SLIDE: lSlideCount = prsntPP.Slides.Count Set slidePP = prsntPP.Slides.Add(Index:=lSlideCount + 1, Layout:=ppLayoutTitleOnly)

.Speed = ppTransitionSpeedFast ‘use the SoundEffect.ImportFromFile Method to specify the sound to play when the slide transition happens – add a .wav format file. Specify the full name and path of the sound file. WAV is a supported audio file format in powerpoint. Note that a supported audio file extension may also not play correctly if the correct codec version is not installed, or if the file is not programmed in a format recognized by your version of Microsoft Windows. .SoundEffect.ImportFromFile “C:\Users\Amit Tandon\Documents\Sound\Audio_2.wav” ‘audio will play till the start of the next sound: .LoopSoundUntilNext = msoTrue .EntryEffect = ppEffectWheel1Spoke .AdvanceOnTime = msoTrue

slidePP.Shapes.Title.TextFrame.TextRange.Text = “Sales Performance – 2012”

‘REFER THE FIRST SHAPE IN THIRD SLIDE – SET TITLE:

.TextFrame.TextRange.Text = “Sales and Profitability Chart” .TextFrame.TextRange.Font.Name = “Verdana” .TextFrame.TextRange.Font.Color = vbYellow .TextFrame.TextRange.Font.Size = 20

.EntryEffect = ppEffectFlyFromTop

‘ADD SECOND SHAPE, AS CHART, IN THIRD SLIDE:

ThisWorkbook.Worksheets(“Sheet3”).

ChartObjects(“SalesPerfChart”).Copy slidePP.Shapes.Paste

Set shapePP = slidePP.Shapes(slidePP.Shapes.Count)

.Top = slidePP.Shapes(slidePP.Shapes.Count – 1).Top + slidePP.Shapes(slidePP.Shapes.Count – 1).Height + 25 .Left = slidePP.Shapes(slidePP.Shapes.Count – 1).Left .Width = slidePP.Shapes(slidePP.Shapes.Count – 1).Width

.Height = 300

.EntryEffect = ppEffectZoomIn .AdvanceMode = ppAdvanceOnTime

.AdvanceTime = 2

‘————————-

‘ADD FOURTH SLIDE: lSlideCount = prsntPP.Slides.Count

‘You use the SlideMaster Property to set the background gradient for all slides, as shown in the beginning. If you want to set the background for an individual slide without affecting other slides, you need to set the FollowMasterBackground property of a slide to False, as shown below. slidePP.FollowMasterBackground = False slidePP.Background.Fill.PresetGradient Style:=msoGradientHorizontal, Variant:=1, PresetGradientType:=msoGradientCalmWater  

msoShapeRectangle, Left:=10, Top:=10, Width:=470, Height:=250) ‘activate the new slide: applPP.ActiveWindow.View.GotoSlide prsntPP.Slides.Count ‘select shape to align: shapePP.Select ‘aligning a shape(s): ‘ShapeRange object represents all slide objects selected in the slide. Align (ie. ShapeRange.Align Method) works with ShapeRange, and not with a Shape, hence selection of a shape is required to use the Selection.ShapeRange Property as below. applPP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, msoTrue applPP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, msoTrue ‘Aligns all shapes in the slide: ‘ slidePP.Shapes.Range.Align msoAlignCenters, msoTrue ‘vertical alignment of textframe in the selected shape: applPP.ActiveWindow.Selection.ShapeRange.

‘REFER THE FIRST SHAPE IN FOURTH SLIDE:

‘Chr(32) adds a space; Chr(13) is carriage return and has the effect of creating a new paragraph: .TextFrame.TextRange.Text = Chr(32) & “We hope to Continue this Strong Performance” & Chr(13) & Chr(13) & Chr(32) & “Thank You Ladies & Gentlemen” & Chr(13) & Chr(13) & Chr(32) & “End of Presentation” .TextFrame.TextRange.ParagraphFormat.

ParagraphFormat.Bullet.Type = ppBulletUnnumbered ‘to add bullets to the last paragraph: ‘.TextFrame.TextRange.Paragraphs(.TextFrame.

TextRange.Paragraphs.Count).

ParagraphFormat.Bullet.Character = 8226 ‘indent last para: .TextFrame.TextRange.Paragraphs(3).IndentLevel = 2 .TextFrame.TextRange.Paragraphs(.TextFrame.

.AdvanceMode = ppAdvanceOnTime ‘You can assign different sound effects for each shape viz. Chime, Appluase, etc. Play the powerpoint sound named Applause: .SoundEffect.Name = “Applause” .TextUnitEffect = ppAnimateByParagraph

TextRange.Paragraphs(1).Lines(1).Font.Italic = True ‘format as italic the second and third lines of the first paragraph in shape four on slide one in the current powerpoint presentation: prsntPP.Slides(1).Shapes(4).TextFrame.

TextRange.Paragraphs(1).Lines(2, 3).Font.Color = vbBlue prsntPP.Slides(1).Shapes(4).TextFrame.

lSlideCount = prsntPP.Slides.Count

‘run the slide show: applPP.ActiveWindow.View.GotoSlide 1

‘use the SlideShowSettings Property to set the slide show settings of the presentation: With prsntPP.SlideShowSettings

‘The SlideShowSettings.Run Method runs a slide show. Use the Run method of the SlideShowSettings to create a new Slide Show Window, and then use the View property to return the Slide Show View (ie. the view in a slide show window). ‘set variable of the SlideShowSettings.Run.View object: Set oSlideShowPP = prsntPP.SlideShowSettings.run.View

‘use the SlideShowView.State Property to return the state of the slide show. ‘the slide show will run till the end of all slides and exit the loop in case of error:

Do Until oSlideShowPP.State = ppSlideShowDone

‘Err.Number = 0 means no error:

If Err.Number <> 0 Then

‘Note that the slide show is being run using the SlideShowSettings.Run method and the SlideShowView.State Property in this example, but the code will not work in PowerPoint 2007 with Late Binding. In the code line — Do Until oSlideShowPP.State = ppSlideShowDone — the built-in constant ppSlideShowDone will need to be replaced by its value of 5 while using Late Binding, which fails while running the code. To automatically run the slide show using late Binding in PowerPoint 2007, see next example.

‘————————- ‘CLOSE PRESENTATION, CLEAR VARIABLES AND QUIT APPLICATION:

‘though this does not actually save the presentation, it avoids a dialog box asking to save changes: prsntPP.Saved = True

‘close presentation prsntPP.Close

‘clear the variables: Set shapePP = Nothing Set slidePP = Nothing Set prsntPP = Nothing Set shapeSoundPP = Nothing Set oSlideShowPP = Nothing      ‘quit PowerPoint application: applPP.Quit

‘clear the variable: Set applPP = Nothing

Example 3: Create a new PowerPoint ppt of 4 slides with sound effects and chart, run & view the slide show, automatically close & quit the PowerPoint application, using Late Binding.

For live code of this example, click to download excel file.

Sub Automating_PowerPoint_from_Excel_3() ‘Automate PowerPoint from Excel, using Late Binding. You need not add a reference to the PowerPoint object library in Excel (your host application), in this case you will not be able to use the PowerPoint’s predefined constants and will need to replace them by their numerical values in your code.

‘Create a new PowerPoint ppt of 4 slides with sound effects and chart, run & view the slide show, automatically close & quit the PowerPoint application.

‘variables declared as Object Type, which can be a reference to any object: Dim oApplPP As Object Dim oPrsntPP As Object Dim oSlidePP As Object Dim oShapePP As Object Dim oSlideShowPP As Object Dim lSlideCount As Long Dim dtSlideAdvanceTime As Date Dim ws As Worksheet Dim strPpPath As String, strPpName As String

‘Set a SlideShowTransition.AdvanceTime of 20 seconds for all slides. This should synchronize with the delay time inserted (at the end) for running the slide show. dtSlideAdvanceTime = 20

‘Create a new instance of the PowerPoint application, if an existing PowerPoint object is not available. ‘Set the Application object as follows: On Error Resume Next Set oApplPP = GetObject(, “PowerPoint.Application”) ‘if an instance of an existing PowerPoint object is not available, an error will occur (Err.Number = 0 means no error):

Set oApplPP = CreateObject(“PowerPoint.Application”)

End If ‘disable error handling: On Error GoTo 0

‘make the PowerPoint window visible: oApplPP.Visible = True ‘maximize PowerPoint window. Built-in constant ppWindowMaximized has been replaced by its numerical value 3: oApplPP.WindowState = 3

‘create a new presentation in PowerPoint: Set oPrsntPP = oApplPP.Presentations.Add ‘set path where to save the new presentation, to the same location as the host workbook: strPpPath = ThisWorkbook.Path ‘set name for the new presentation with the defined path as determined above: strPpName = strPpPath & “\” & “newPresentation1.pptx”

‘saves the new presentation, with the specified name and path: oPrsntPP.SaveAs Filename:=strPpName

‘use the SlideMaster Property to set the background gradient for all slides: ‘Built-in constants msoGradientHorizontal and msoGradientDaybreak have been replaced by their numerical values of 1 and 4: oPrsntPP.SlideMaster.Background.Fill.

PresetGradient Style:=1, Variant:=1, PresetGradientType:=4

‘————————- ‘ADD FIRST SLIDE: ‘The title slide (ppLayoutTitleOnly) has 1 shape, Shape(1) is the title, you can add your own shapes to the slide: ‘Add a title slide to the new presentation. Built-in constant ppLayoutTitleOnly has been replaced by its value 11. Set oSlidePP = oPrsntPP.Slides.Add(Index:=1, Layout:=11)

‘use the SlideShowTransition Property to determine how the slide advances in a slide show: With oSlidePP.SlideShowTransition

‘Built-in constant ppTransitionSpeedFast has been replaced by its value 3. .Speed = 3 ‘Built-in constant ppEffectWedge has been replaced by its value 3856. .EntryEffect = 3856 ‘set AdvanceOnTime property to true for the slide to advance automatically after the specified time gap: ‘Built-in constant msoTrue has been replaced by its value -1. .AdvanceOnTime = -1 ‘AdvanceTime Property sets the time gap in seconds for the specified slide transition. ‘set the slide advance time of 20 seconds before it advances to the next slide:

.AdvanceTime = dtSlideAdvanceTime

‘REFER FIRST SHAPE IN FIRST SLIDE: ‘Text Frame refers to the area within a shape that holds text and it has properties and methods to control its alignment and anchoring. ‘TextRange refers to text in a shape and it has properties and methods to add and manipulate text. ‘set the title text on the slide: oSlidePP.Shapes.Title.TextFrame.TextRange.Text = “Sales Performance – 2012”

‘ADD SECOND SHAPE IN FIRST SLIDE: ‘Create a new shape in the slide. Built-in constant msoShapeOval has been replaced by its value 9. Set oShapePP = oSlidePP.Shapes.AddShape(Type:=9, Left:=50, Top:=150, Width:=120, Height:=90)

With oShapePP

.Fill.ForeColor.RGB = RGB(255, 0, 0) .TextFrame.TextRange.Text = “Presented by Scott Kelly” .TextFrame.TextRange.Font.Name = “Arial” .TextFrame.TextRange.Font.Size = 12 ‘Built-in constant msoTrue has been replaced by its value -1. .TextEffect.FontBold = -1

‘Built-in constant ppAdvanceOnTime has been replaced by its value 2. .AdvanceMode = 2 .AdvanceTime = 2 .SoundEffect.Name = “Wind” ‘Built-in constant ppEffectFlyFromLeft has been replaced by its value 3329. .EntryEffect = 3329 ‘use TextUnitEffect Property to determine how the text is animated – by paragraph, by word, or by letter: ‘Built-in constant ppAnimateByParagraph has been replaced by its value 0.

.TextUnitEffect = 0

‘ADD THIRD SHAPE IN FIRST SLIDE: ‘create a new shape in the slide: ‘Built-in constant msoShape8pointStar has been replaced by its value 93. Set oShapePP = oSlidePP.Shapes.AddShape(Type:=93, Left:=220, Top:=200, Width:=250, Height:=270)

.Name = “Company” .Fill.ForeColor.RGB = RGB(0, 255, 0) ‘Built-in constant msoLineThickThin has been replaced by its value 4. .Line.Style = 4

.TextFrame.TextRange.Font.Name = “Arial” .TextFrame.TextRange.Font.Size = 18 ‘Built-in constant msoTrue has been replaced by its value -1.

.TextEffect.FontBold = -1

‘Set the AnimationSettings.AdvanceMode Property to ppAdvanceOnTime, for the animation to start automatically after the specified time gap. ‘Built-in constant ppAdvanceOnTime has been replaced by its value 2. .AdvanceMode = 2 ‘animate specified shape automatically after 2 seconds: .AdvanceTime = 2 .SoundEffect.Name = “Wind” ‘Built-in constant ppEffectFlyFromLeft has been replaced by its value 3329. .EntryEffect = 3329 ‘The AnimationSettings.TextLevelEffect Property determines the paragraph level by which the text in a shape gets animated: ‘Built-in constant ppAnimateBySecondLevel has been replaced by its value 2. .TextLevelEffect = 2 ‘Built-in constant ppAnimateByCharacter has been replaced by its value 2.

.TextUnitEffect = 2

‘————————- ‘ADD SECOND SLIDE: lSlideCount = oPrsntPP.Slides.Count

‘The text slide (ppLayoutText)has 2 shapes wherein text can be inserted, Shape(1) is the title, and Shape(2) is the bulleted text area: ‘Built-in constant ppLayoutText has been replaced by its value 2. Set oSlidePP = oPrsntPP.Slides.Add(Index:=lSlideCount + 1, Layout:=2)

With oSlidePP.SlideShowTransition

‘Built-in constant ppTransitionSpeedFast has been replaced by its value 3. .Speed = 3 ‘Built-in constant ppEffectUncoverDown has been replaced by its value 2052. .EntryEffect = 2052 ‘Built-in constant msoTrue has been replaced by its value -1. .AdvanceOnTime = -1

With oSlidePP.Shapes(1)

.TextFrame.TextRange.Font.Name = “Verdana” .TextFrame.TextRange.Font.Color = vbYellow .TextFrame.TextRange.Font.Size = 20 ‘Built-in constant msoTrue has been replaced by its value -1.

‘Built-in constant ppAdvanceOnTime has been replaced by its value 2. .AdvanceMode = 2 .AdvanceTime = 1 .SoundEffect.Name = “Camera” ‘Built-in constant ppAnimateByParagraph has been replaced by its value 0. .TextUnitEffect = 0 ‘Built-in constant ppEffectFlyFromRight has been replaced by its value 3331.

.EntryEffect = 3331

With oSlidePP.Shapes(2)

‘use the TextRange.ParagraphFormat Property to do paragraph formatting for the specified text. ‘this shape is the bulleted text area, here we are changing the bullet type: ‘Built-in constant ppBulletNumbered has been replaced by its value 2. .TextFrame.TextRange.ParagraphFormat.

Bullet.Type = 2 Set ws = ThisWorkbook.Sheets(“Sheet1”)

.TextFrame.TextRange.Text = Trim(ws.Range(“A1”)) & Chr(13) & Chr(13) & Trim(ws.Range(“A2”)) & Chr(13) & Chr(13) & Trim(ws.Range(“A3”)) & Chr(13) & Chr(13) & Trim(ws.Range(“A4”)) & Chr(13) & Chr(13) & Trim(ws.Range(“A5”)) & Chr(13) & Chr(13) & Trim(ws.Range(“A6”)) .TextFrame.TextRange.Font.Name = “Times New Roman” .TextFrame.TextRange.Font.Size = 18 .TextFrame.TextRange.Font.Color = RGB(0, 0, 255) ‘Built-in constant msoTrue has been replaced by its value -1. .TextEffect.FontBold = -1

‘Built-in constant ppAdvanceOnTime has been replaced by its value 2. .AdvanceMode = 2 .AdvanceTime = 1 .SoundEffect.Name = “Camera” ‘Built-in constant ppAnimateByParagraph has been replaced by its value 0. .TextUnitEffect = 0 ‘Built-in constant ppAnimateBySecondLevel has been replaced by its value 2. .TextLevelEffect = 2 ‘Built-in constant ppEffectFlyFromRight has been replaced by its value 3331.

‘————————- ‘ADD THIRD SLIDE: lSlideCount = oPrsntPP.Slides.Count

‘Built-in constant ppLayoutTitleOnly has been replaced by its value 11. Set oSlidePP = oPrsntPP.Slides.Add(Index:=lSlideCount + 1, Layout:=11)

‘Built-in constant ppTransitionSpeedFast has been replaced by its value 3. .Speed = 3 ‘Built-in constant ppEffectWheel1Spoke has been replaced by its value 3857. .EntryEffect = 3857 ‘Built-in constant msoTrue has been replaced by its value -1. .AdvanceOnTime = -1

oSlidePP.Shapes.Title.TextFrame.TextRange.Text = “Sales Performance – 2012”

.TextFrame.TextRange.Text = “Sales and Profitability Chart” .TextFrame.TextRange.Font.Name = “Verdana” .TextFrame.TextRange.Font.Color = vbYellow .TextFrame.TextRange.Font.Size = 20 ‘Built-in constant msoTrue has been replaced by its value -1.

‘Built-in constant ppAdvanceOnTime has been replaced by its value 2. .AdvanceMode = 2 .SoundEffect.Name = “Camera” ‘Built-in constant ppAnimateByParagraph has been replaced by its value 0. .TextUnitEffect = 0 ‘Built-in constant ppEffectFlyFromTop has been replaced by its value 3330.

.EntryEffect = 3330

ThisWorkbook.Worksheets(“Sheet2”).

ChartObjects(“SalesPerfChart”).Copy oSlidePP.Shapes.Paste

Set oShapePP = oSlidePP.Shapes(oSlidePP.Shapes.Count)

.Top = oSlidePP.Shapes(oSlidePP.Shapes.Count – 1).Top + oSlidePP.Shapes(oSlidePP.Shapes.Count – 1).Height + 25 .Left = oSlidePP.Shapes(oSlidePP.Shapes.Count – 1).Left .Width = oSlidePP.Shapes(oSlidePP.Shapes.Count – 1).Width

‘Built-in constant ppEffectZoomIn has been replaced by its value 3345. .EntryEffect = 3345 ‘Built-in constant ppAdvanceOnTime has been replaced by its value 2. .AdvanceMode = 2 .AdvanceTime = 2 .SoundEffect.Name = “Chime” ‘Built-in constant ppAnimateByParagraph has been replaced by its value 0.

‘————————- ‘ADD FOURTH SLIDE: lSlideCount = oPrsntPP.Slides.Count

‘Being a blank slide (ppLayoutBlank), it has no shapes, you can add your shapes to the slide: ‘Built-in constant ppLayoutBlank has been replaced by its value 12. Set oSlidePP = oPrsntPP.Slides.Add(Index:=lSlideCount + 1, Layout:=12)

‘You use the SlideMaster Property to set the background gradient for all slides, as shown in the beginning. If you want to set the background for an individual slide without affecting other slides, you need to set the FollowMasterBackground property of a slide to False, as shown below. oSlidePP.FollowMasterBackground = False oSlidePP.Background.Fill.PresetGradient Style:=msoGradientHorizontal, Variant:=1, PresetGradientType:=msoGradientCalmWater

‘Built-in constant ppTransitionSpeedSlow has been replaced by its value 1. .Speed = 1 ‘Built-in constant ppEffectBoxOut has been replaced by its value 3073. .EntryEffect = 3073 ‘Built-in constant msoTrue has been replaced by its value -1. .AdvanceOnTime = -1

‘create a new shape in the slide: Set oShapePP = oSlidePP.Shapes.AddShape(Type:=

‘activate the new slide: oApplPP.ActiveWindow.View.GotoSlide oPrsntPP.Slides.Count ‘select shape to align: oShapePP.Select ‘aligning a shape(s): ‘ShapeRange object represents all slide objects selected in the slide. Align (ie. ShapeRange.Align Method) works with ShapeRange, and not with a Shape, hence selection of a shape is required to use the Selection.ShapeRange Property as below. ‘Built-in constants msoAlignCenters & msoTrue have been replaced by their numerical values 1 and -1: oApplPP.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, -1 ‘Built-in constants msoAlignMiddles & msoTrue have been replaced by their numerical values 4 and -1: oApplPP.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, -1

‘Aligns all shapes in the slide: ‘Built-in constants msoAlignCenters & msoTrue have been replaced by their numerical values 1 and -1: ‘oSlidePP.Shapes.Range.Align 1, -1

‘vertical alignment of textframe in the selected shape: ‘Built-in constant msoAnchorTop has been replaced by its value 1. oApplPP.ActiveWindow.Selection.ShapeRange.

TextFrame2.VerticalAnchor = 1

‘Built-in constant ppAlignJustify has been replaced by its value 4. .TextFrame.TextRange.ParagraphFormat.

Alignment = 4 ‘Add bullets to all text in the range. Built-in constant ppBulletUnnumbered has been replaced by its value 1. .TextFrame.TextRange.ParagraphFormat.

Bullet.Type = 1 ‘To add bullets to the first paragraph. Built-in constant ppBulletUnnumbered has been replaced by its value 1.: ‘.TextFrame.TextRange.Paragraphs(1).

ParagraphFormat.Bullet.Type = 1 ‘to add bullets to the last paragraph: ‘.TextFrame.TextRange.

Count).ParagraphFormat.Bullet.Character = 8226

‘indent last para: .TextFrame.TextRange.Paragraphs(3).IndentLevel = 2 .TextFrame.TextRange.Paragraphs(.TextFrame.

TextRange.Paragraphs.Count).IndentLevel = 3 .TextFrame.TextRange.Font.Name = “Times New Roman” .TextFrame.TextRange.Font.Size = 20 .TextFrame.TextRange.Font.Color = RGB(0, 255, 0) ‘Built-in constant msoTrue has been replaced by its value -1:

‘Built-in constant ppAdvanceOnTime has been replaced by its value 2: .AdvanceMode = 2 ‘You can assign different sound effects for each shape viz. Chime, Appluase, etc. Play the powerpoint sound named Applause: .SoundEffect.Name = “Applause” ‘Built-in constant ppAnimateByParagraph has been replaced by its value 0: .TextUnitEffect = 0 ‘Built-in constant ppAnimateBySecondLevel has been replaced by its value 2. .TextLevelEffect = 2 ‘Built-in constant ppEffectCheckerboardAcross has been replaced by its value 1025:

.EntryEffect = 1025

‘refer shape by its name: oPrsntPP.Slides(1).Shapes(“Company”).TextFrame.

TextRange.Paragraphs(1).Lines(1).Font.Italic = True ‘format as italic the second and third lines of the first paragraph in shape three on slide one in the current powerpoint presentation: oPrsntPP.Slides(1).Shapes(3).TextFrame.TextRange.

Paragraphs(1).Lines(2, 3).Font.Color = vbBlue oPrsntPP.Slides(1).Shapes(3).TextFrame.TextRange.

Paragraphs(3).Lines(1).Font.Underline = True

‘save the presentation: oPrsntPP.Save

‘minimize Excel window: ‘Built-in constant xlMinimized has been replaced by its value -4140. Application.WindowState = -4140

lSlideCount = oPrsntPP.Slides.Count Dim iSlideIndexPP As Integer

‘The SlideShowSettings.Run Method runs a slide show. Use the Run method of the SlideShowSettings to create a new Slide Show Window, and then use the View property to return the Slide Show View (ie. the view in a slide show window). ‘To set variable of the SlideShowSettings.Run.View object, use the following code. Note that this creates a new slide show window. ‘Set oSlideShowPP = oPrsntPP.SlideShowSettings.run.View

‘the slide show will run till the end of all slides: For iSlideIndexPP = 1 To lSlideCount

‘this will avoid an error message while running the slide show and will exit the For…Next loop:

On Error GoTo ErrorLine

If iSlideIndexPP = 1 Then

‘the slide show window view would have repeated if the object variable oSlideShowPP had been set before the For…Next statement:

Set oSlideShowPP = oPrsntPP.SlideShowSettings.run.View

oSlideShowPP.GotoSlide iSlideIndexPP

‘Insert a delay time before continuing to next slide. This will ensure that the slide show remains visible while running, else the slides will not be able to hold view. ‘The time set of 20 seconds is equivalent to (it is necessary to synchronize) the standard SlideShowTransition.AdvanceTime set for all slides.

Application.Wait Now + TimeValue(“00:00:20”)

Next iSlideIndexPP

  ‘Note that the slide show could have also been run using the SlideShowSettings.Run method and the SlideShowView.State Property as shown in the previous example, but the code will not work in PowerPoint 2007 with Late Binding. In the code line — Do Until oSlideShowPP.State = ppSlideShowDone — the built-in constant ppSlideShowDone will need to be replaced by its value of 5 while using Late Binding, which fails while running the code.

ErrorLine: ‘though this does not actually save the presentation, it avoids a dialog box asking to save changes: oPrsntPP.Saved = True oPrsntPP.Close oApplPP.Quit Exit Sub

‘though this does not actually save the presentation, it avoids a dialog box asking to save changes: oPrsntPP.Saved = True

‘close presentation oPrsntPP.Close

‘clear the variables: Set oShapePP = Nothing Set oSlidePP = Nothing Set oPrsntPP = Nothing Set oSlideShowPP = Nothing      ‘quit PowerPoint application: oApplPP.Quit

‘clear the variable: Set oApplPP = Nothing

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

Supercharging PowerPoint interactive presentations with VBA (Part 1)

  • Written by: Jamie Garroch
  • Categories: PowerPoint productivity , Presentation technology
  • Comments: 10

powerpoint vba get current presentation

PowerPoint has evolved into an app which is the Swiss Army knife of content creation, not only for presentations, but also printed collateral, videos and even interactive presentations.

Imagine you have to use a file containing all the slides you could possibly present to your audience knowing that you will only present a small subset of them at any one time. That’s where interactive presentations can be a powerful addition to your presentation arsenal. It’s a bit like visiting a website and only clicking on the pages you’re interested in as opposed to visiting every single page. Interactive presentations provide you with the ability to quickly react to your audience by jumping around your content live instead of having to say: “I’ll come to that later” and then forgetting!

The interactivity element provides the presenter with the ability to click on objects on their slide which then takes them to a specific location in the presentation.

Interactive presentations: The basics

I’ll use a basic example like the slide below to show you how to add interactivity to your presentation. There is a menu on the left-hand side of the slide which we’ve built with various shapes. Let’s say you want use this to give the presenter the ability to jump to either the next or previous slide:

basic un-hyperlinked slide

The first thing you need to do is select the object you want to make interactive:

BrightCarbon VBA supercharged interactive presentation screenshot 1b

You then need to link it to another slide. The functionality required to achieve the linking is simple and utilises a long-standing feature of PowerPoint called Actions . You can find this feature in the Insert tab of the PowerPoint ribbon:

PowerPoint ribbon with Action tab selected

When you click the Action button, you get a plethora of options in two tabs as you can see:

BrightCarbon VBA supercharged interactive presentation screenshot 2b

These tabs allow you to set links for either or both of two mouse actions, Mouse Click and Mouse Over (or ‘mouse hover’).

The one you’ll probably use the most is Mouse Click and you can use the Hyperlink to dropdown to link to one of several built-in navigation options:

BrightCarbon VBA supercharged interactive presentation screenshot 3

Again, the ones you’ll probably use when creating interactive presentations are Next Slide , Previous Slide and Slide… where you can choose a specific slide to link to.

Once you’ve added the action to your object you can click on it in slide show mode and it will take you to whatever slide or content you chose to link to.

The Animation Challenge

One aspect of creating interactive presentations is that if you combine the above action technique with animation, the animations are not reset automatically when you return to a slide that has already been presented. This might be an issue if you want to either replay the animation sequence or if you’ve used animation triggers to show and hide your menu. In the later case, the menu would remain on screen when you return to a previously presented slide and that means the presenter must spend time hiding it again.

So, what can you do about this?

Technique 1: Duplicate Slide

There is a native non-VBA technique you can use which is to create a duplicate of the slide without animations and set it to automatically transition to the next slide on zero seconds as seen in the top-right of the ribbon here:

BrightCarbon VBA supercharged interactive presentation screenshot 4

You then change the action hyperlink to point to this duplicate slide instead of the one with the animations. This forces the animation on the slide you want to show to reset.

Technique 2: VBA Magic

The challenge with the above technique is that you must now maintain two copies of every slide in the presentation and secondly, remember to set the links to the auto-transition slide, not the slide you will present. This can make your interactive presentations into much more cumbersome files with more slides than is really necessary, subsequently making them more difficult to maintain.

You can avoid having to do this by adding a couple of VBA macros to our project. If you’re not familiar with how to add VBA to your presentation, have a look at our blog article showing you how to do it.

You’re going to create two VBA macros to go to the next slide and previous slide, both of which will reset the animations on the target slide. The full code is available at the end of this article.

Here is the VBA code for the next slide macro:

Once you have this code in our project you can go back to the Insert/Action dialog and change the mouse click action to run our custom macro:

BrightCarbon VBA supercharged interactive presentation screenshot 5

How does it work?

The opening line of the macro passes the shape you clicked on to the macro:

Public Sub NextSlide(ByRef oShp As Shape)

This allows us to determine which slide you’re on by setting a reference to the shape’s parent object, which is the slide:

Set oSld = oShp.Parent

You can now find out what the slide index is for this slide and increment it by one:

lIdx = oSld.SlideIndex + 1

You need to handle what happens if you’re on the last slide and you’ve chosen to link back to the first slide in that case:

If lIdx = ActivePresentation.Slides.Count Then lIdx = 1

The last step is to actually tell PowerPoint to go to this slide:

SlideShowWindows(1).View.GotoSlide lIdx, msoTrue

The magic part of this is the tiny msoTrue on the end of the line. The GotoSlide method (think of a method as an action verb) takes two arguments. The first is the slide index you want to go to and the second is a boolean option to tell PowerPoint to reset the animation for that slide, or not.

Now when you click any object that has this macro assigned to the Mouse Click action, the slide show will go to that slide and reset the animations.

BrightCarbon PowerPoint Trust Center Settings for Macros

Now that you know how to use VBA when creating interactive presentations, check out my post on restoring default slide master layouts with VBA. or discover our Click-and-Explore service to find out how we can help create your next beautifully-designed interactive presentation.

Full code for Next, Previous and Reset Animation macros

You can copy and paste the full code from below into your VBA project. The PreviousSlide macro works just like the NextSlide one with a small adjustment to loop to the last slide if you’re on the first slide.

There is also a simpler ResetCurrentSlide macro which you can assign to any shape on your slide or slide master or layout which just resets the animations for the current slide.

Navigating to a specific slide

This concept can be taken further should you wish to navigate to a specific numbered slide. You need a way to pass the number of the slide you want to navigate to into the macro. A nice and easy way to do this is to use the name of the shape you assign the click action to. Open the Selection Pane by pressing the very secret shortcut Alt+F10 (or clicking the Home tab followed by Arrange / Selection Pane ) and change the name of your clickable shape to “5” for example. Now link that shape to the macro below:

Got something extra you’d like PowerPoint to do?

Check out our PowerPoint automation service which provides you with a custom solution to your specific needs.

powerpoint vba get current presentation

Jamie Garroch

Principal technical consultant, related articles, how to consistently brand graphs and charts across microsoft office.

  • PowerPoint design / PowerPoint productivity
  • Comments: 1

How do you make sure that your graphs and charts have consistent branding across Excel, PowerPoint and Word? Learn how to create and use custom templates that support your brand identity across Microsoft Office.

powerpoint vba get current presentation

Changes to VBA Macro Security in Microsoft 365

  • Presentation technology / Industry insights
  • Comments: 2

You can do some really cool things in Microsoft Office with just a few lines of Visual Basic for Applications (VBA) - from creating your own custom formula in Excel to correcting branded content in PowerPoint to merging address data for a mail campaign in Word. And sometimes you need to share that VBA solution with colleagues and clients, via the Internet. A change that Microsoft rolled out at the end of March 2022 tweaks the process required by Windows users to gain access to this active content.

powerpoint vba get current presentation

Protecting your prized PowerPoint content

  • PowerPoint productivity / Presentation technology

Our comprehensive guide to password protecting PowerPoint files so your precious presentations stay just they you made them!

Best methods you have shared here to make interactive presentation in Power Point.

Thanks Aira!

You have come forward with the top methods to make interactive presentations with Power Point.

Thank you SOOO much for this — what a wonderful resource. Extremely well explained all the way through.

Question: is there a similar way to what you’ve described above that would allow me to target a specific slide number. I can see that i could do the math (+ or – X number of slides), but then i’d need a new macro for every slide. If there are any solutions for this, i would greatly appreciate it.

Hi Daniel. Glad it’s helpful for you. I think the easiest way to achieve this would be to use the name of the object and pass it to the navigation macro. For example, if you create a shape on a slide, change it’s name to “5” in the Selection Pane (Alt+F10) and then link it to the GoToSlide macro above then that would do what you want.

hii, thanks for that. one question, in the end, can I convert my ppt to pdf or another format in a way that the content will be no edible ?

Thanks for all the great advice. I’m trying to create a PowerPoint where text entered on the first slide populates text boxes in later slides. Any suggestions?

Hi sufyan and thank you for the question. You can convert any PowerPoint file to a PDF regardless of the source file format e.g. a pptx or a code-enabled pptm, even a ppsx/ppsm slide show. But, any VBA code will be stripped out as Adobe doesn’t support it and hence the functionality provided by that code will be lost. I hope that helps.

Thanks for all the great advice. I’m trying to create a PowerPoint where text entered on the first slide populates text boxes in later slides. Any suggestions?

Hi Kieran. You could do that with VBA. One decision to be made upfront is what triggers the update. It’s possible to detect when users are editing text but that’s a very involved development. Alternatively, if it’s just you using the solution then a simple macro could work which you manually call using Alt+F8. The simple example below will copy the text from the selected object to any other shape with the same name (use Alt+F10 to open the Selection pane to name objects) that it finds in the presentation:

Sub CopyTextFromSelectionToSameNamedObjects() Dim oShpSrc As Shape, oShpTgt As Shape Dim strText As String Dim oSld As Slide

On Error Resume Next ‘ Error handling off!

Set oShpSrc = ActiveWindow.Selection.ShapeRange(1)

If oShpSrc Is Nothing Then Exit Sub

If oShpSrc.HasTextFrame Then strText = oShpSrc.TextFrame.TextRange.Text Else Exit Sub End If

For Each oSld In ActivePresentation.Slides For Each oShpTgt In oSld.Shapes If Not oShpSrc Is oShpTgt Then If UCase(oShpTgt.Name) = UCase(oShpSrc.Name) Then If oShpTgt.HasTextFrame Then oShpTgt.TextFrame.TextRange.Text = strText End If End If Next Next End Sub

If you’d like us to develop this further for you, please use our Contact form.

Leave a Reply Cancel reply

Save my name and email in this browser for the next time I comment.

Join the BrightCarbon mailing list for monthly invites and resources

No one was looking at their electronics; all eyes were on the podium. We raised the bar on what a great presentation is supposed to look like. Curtis Waycaster Smith & Nephew

powerpoint vba get current presentation

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Presentation.Path property (PowerPoint)

  • 8 contributors

Returns a String that represents the path to the specified Presentation object. Read-only.

expression . Path

expression A variable that represents a Presentation object.

Return value

If you use this property to return a path for a presentation that has not been saved, it returns an empty string.

The path doesn't include the final backslash () or the name of the specified object. Use the Name property of the Presentation object to return the file name without the path, and use the FullName property to return the file name and the path together.

This example saves the active presentation in the same folder as PowerPoint.

Presentation Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.

Was this page helpful?

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback .

Submit and view feedback for

Additional resources

IMAGES

  1. How to use VBA in PowerPoint: A beginner's guide

    powerpoint vba get current presentation

  2. VBA PowerPoint

    powerpoint vba get current presentation

  3. PowerPoint Automation using VBA. Complete professional course for free

    powerpoint vba get current presentation

  4. How to use VBA in PowerPoint: A beginner's guide

    powerpoint vba get current presentation

  5. How to use VBA in PowerPoint: A beginner's guide

    powerpoint vba get current presentation

  6. VBA PowerPoint

    powerpoint vba get current presentation

VIDEO

  1. POWERPOINT VBA TO START ANIMATION ON KEY PRESS

  2. VBA PPT Part 1

  3. How to use VBA-code for a PPT on a Mac

  4. VBA for Power Point Presentation

  5. Powerpoint VBA : การสร้างแบบทดสอบที่เก็บคะแนนลงฐานข้อมูล

  6. Tutorial VBA Powerpoint 2007 Browsed at a kiosk

COMMENTS

  1. Getting the Active Slide of a PPT Presentation via VBA (but from Excel

    That code is dangerously ambiguous about what instance of PPT it's working with. Why to you need ppApp, when PowerPoint is already an active PowerPoint.Application instance? And if the PPT type library is referenced, you don't need to CreateObject, it's uselessly inefficient... just New it up. When the code stops running, make sure you bring up Task Manager and verify that all powerpoint.exe ...

  2. Application.ActivePresentation property (PowerPoint)

    In this article. Returns a Presentation object that represents the presentation open in the active window. Read-only. Syntax. expression.ActivePresentation. expression A variable that represents an Application object.. Return value. Presentation. Remarks. If an embedded presentation is in-place active, the ActivePresentation property returns the embedded presentation.

  3. In PowerPoint VBA, how do I refer to the ACTIVE slide?

    I want to be able to insert an object on the active slide in VBA code. I could only find. ActivePresentation.Slides(2).Shapes.Addshape... like I have to refer to a particular slide rather than the active one. I'm sure it can be done, but couldn't find it by browsing the object browser. TIA . Bob Umlas. Excel MVP

  4. Application.Active property (PowerPoint)

    Office VBA reference topic. Example. This example checks to see if the presentation file "test.ppt" is in the active window. If not, it saves the name of the presentation that is currently active in the variable oldWin and activates the "test.ppt" presentation.. With Application.Presentations("test.ppt").Windows(1) If Not .Active Then Set oldWin = Application.ActiveWindow .Activate End If End With

  5. PowerPoint VBA Macro Examples & Tutorial

    This is a simple example of a PowerPoint VBA Macro: Sub SavePresentationAsPDF() Dim pptName As String Dim PDFName As String ' Save PowerPoint as PDF. pptName = ActivePresentation.FullName. ' Replace PowerPoint file extension in the name to PDF. PDFName = Left(pptName, InStr(pptName, ".")) & "pdf".

  6. Determine The Current ActiveShape In PowerPoint With VBA

    Dim shp As Shape. 'Determine Which Shape is Active If ActiveWindow.Selection.Type = ppSelectionShapes Then 'Loop in case multiples shapes selected For Each shp In ActiveWindow.Selection.ShapeRange. 'ActiveShape is first shape selected Set ActiveShape = shp. Exit For Next shp.

  7. How to use VBA in PowerPoint: A beginner's guide

    Getting to meet your VBA friend is very simple. With PowerPoint open and at least one presentation file open, press Alt+F11* on your keyboard. This will open the VBE (Visual Basic Editor): *If for some reason Alt+F11 isn't mapped on your keyboard you can right click anywhere on the ribbon, select Customize the Ribbon… and in the window that ...

  8. VBA PowerPoint

    Select "Visual Basic" in the Workbook. It will open the Excel VBA Editor. Step 2: On opening the VBA Editor and Module, go to "Tools" > "References.". It will open a Window. Step 3: Select "Microsoft Office 16.0 Access Database Engine Object" from the References. Step 4: Also select "Microsoft PowerPoint 16.0 Object Library.".

  9. Powerpoint VBA Reference Library

    The complete program for saving time by automating Excel. Discover the 7-step framework for automating Excel. Start using Office Scripts and Power Automate to automate Excel in new ways. The code below is intended to be a basic reference to anybody trying to use VBA code for Powerpoint. It's certainly not complete, but it is code I've used.

  10. Presentations object (PowerPoint)

    Use Presentations ( index ), where index is the presentation's name or index number, to return a single Presentation object. The following example prints presentation one. Use the Open method to open a presentation and add it to the Presentations collection. The following example opens the file Sales.ppt as a read-only presentation.

  11. Automate Microsoft PowerPoint from Excel, using vba, Run a Slide Show

    applPP.Quit. 'clear the variable: Set applPP = Nothing. End Sub. Example 3: Create a new PowerPoint ppt of 4 slides with sound effects and chart, run & view the slide show, automatically close & quit the PowerPoint application, using Late Binding. For live code of this example, click to download excel file.

  12. PDF PowerPoint VBA

    • Saves the presentation as a PDF PowerPoint Application Open a New Presentation When VBA code is running within a PowerPoint Presentation, PowerPoint Application is the default application and it can be manipulated without explicitly reference. Create a New Presentation To create a presentation, use the Add method of PowerPoint application.

  13. Supercharging PowerPoint interactive presentations with VBA (Part 1

    If lIdx = ActivePresentation.Slides.Count Then lIdx = 1. The last step is to actually tell PowerPoint to go to this slide: SlideShowWindows (1).View.GotoSlide lIdx, msoTrue. The magic part of this is the tiny msoTrue on the end of the line. The GotoSlide method (think of a method as an action verb) takes two arguments.

  14. Presentation.FullName property (PowerPoint)

    expression A variable that represents a Presentation object. Return value. String. Remarks. This property is equivalent to the Path property, followed by the current file system separator, followed by the Name property. Example. This example displays the path and file name of every available add-in. For Each a In Application.AddIns MsgBox a ...

  15. PowerPoint Visual Basic for Applications (VBA) reference

    This reference contains conceptual overviews, programming tasks, samples, and references to guide you in developing solutions based on PowerPoint. Note. Interested in developing solutions that extend the Office experience across multiple platforms? Check out the new Office Add-ins model. Use the table of contents in the navigation on the left ...

  16. Slide.SlideNumber property (PowerPoint)

    In this article. Returns the slide number. Read-only. Syntax. expression.SlideNumber. expression A variable that represents a Slide object.. Return value. Integer. Remarks. The SlideNumber property of a Slide object is the actual number that appears in the lower-right corner of the slide when you display slide numbers. This number is determined by the number of the slide within the ...

  17. VBA Powerpoint. How to get file's current directory path to a string in

    If the presentation file has not been saved yet this property will contain an empty string. To test this out you could use something like: Sub test() Dim sPath As String. sPath = ActivePresentation.Path. If Len(sPath) > 0 Then. MsgBox ActivePresentation.Name & vbNewLine & "saved under" & vbNewLine & sPath. Else. MsgBox "File not saved".

  18. Presentation.Path property (PowerPoint)

    Remarks. If you use this property to return a path for a presentation that has not been saved, it returns an empty string. The path doesn't include the final backslash () or the name of the specified object. Use the Name property of the Presentation object to return the file name without the path, and use the FullName property to return the ...

  19. excel

    The way to set a variable of the current slide is. foo = ActiveWindow.Selection.SlideRange.SlideIndex. So then call the function with Call slide2(slidesCount) Try the following. Sub CreatePres() Dim ppApp As PowerPoint.Application. Dim ppPres As PowerPoint.Presentation. Dim ppSlide As PowerPoint.Slide.