Microsoft Powerpoint - Using Macro to add Multiple Slides to A Presentation

Asked By Melissa on 06-Mar-10 02:46 PM
Hello,

I'm learning VBA and have been trying to figure out how to write a macro that will randomly assign different background colors to slides in a presentation.  As I've been working through what I can find online & in the help menus in Powerpoint, I've realized I can expand my original idea to create a macro that will generate my whole presentation...and the first step will be to ask the user how many slides should be in the presentation, then have the macro insert that many slides.  I know I need to assign the user response to a variable, and I know I need to use the Add method, but I have been totally unsuccessful at figuring out how to insert a specific number of slides - the Add method seems to want to insert them by slide number, and only in the range of numbers that already exist in the presentation.  So if I have 3 slides, and I want to do Add 2, it'll add Slide 2, but not 2 more slides. 

I can't find the correct syntax for the add method ANYWHERE - hours of searching to no avail.  Can anyone help me with this?  I can probably figure out how to do the variable assignment, and I'd prefer to sort it out on my own because then I'll remember it better, but just for fun, I'll also put my whole project outline here:

I teach Latin & I want a macro that first prompts me for the number of slides to insert into the presentation, then for each slide, prompts me to input a form (grammar drills...).  Then after I've inputted my forms, the macro will automatically insert a textbox on each slide, with each form on its own slide, font maximized so that it's as big as it can get without wrapping (that might be tricky), center the text box vertically & horizontally on each slide, and then randomly assign fonts & background colors.  I know I need to use loops. 

I can find a lot of support for changing colors of shapes, but not for changing slide background colors.  I don't want to play with color schemes, I don't think, and I am fairly sure that if I can get the code right, it's just a question of telling the thing to loop as many times as the user response was in the first input.   As I'm new to VBA (but not so new to programming, though out of practice), I'm having some learning curves with the syntax & the vocabulary. 

I'll be grateful for any suggestions at all - I've spent almost 3 days on this already, and I'm going nuts.  Oh, also - I'm using PowerPoint 2003 at work, and 2007 at home.  I'm assuming if I can figure it out in 2007 I can make it work in 2003. 

Thanks in advance!!

Melissa
F Cali replied to Melissa on 06-Mar-10 11:23 PM
Here's how to add a slide using VB macro, taken from the following link: http://www.vbaexpress.com/kb/getarticle.php?kb_id=177

Option Explicit

Sub AddSlides()
    
    Dim Pre             As Presentation
    Dim Sld             As Slide
    
    Set Pre = ActivePresentation
    Set Sld = Pre.Slides.Add(Index:=Pre.Slides.Count + 1, Layout:=ppLayoutText)
    Sld.Shapes(1).TextFrame.TextRange = "Title of Slide"
    Sld.Shapes(2).TextFrame.TextRange = "Line 1" & vbNewLine & _
    "Line 2" & vbNewLine & _
    "Line 3" & vbNewLine & _
    "Line 4" & vbNewLine
    
End Sub


Just call this sub-routine the for the certain number of slides you want to add.  It will always add the slide at the end of the power point.

Regards,
SQL Server Helper