VBA for Powerpoint question

G

Guest

I want to do this:

slide 1 (a, b, c, d)
slide 2(a, c)
slide 3(a, b, d)
slide 4(b, d)

I want to then look through the list, and, depending on which presentation
audience (indicated by the a, b, c, or d) I want to construct the
presentation for, I want to write code that says, look at each slide, and
copy all the slides with the indicator "c" into a new, blank presentation.

The slides already exist in master presentations. I don't want to merely use
the "custom show" feature in PowerPoint because I want the slides in a
separate presentation each time I use them because they will require further
modifications once I create them, and I don't want to simply open a separate
master every time I want to work on my presentations because I will want to
make global changes on occassion.

I've perused the PowerPoint Help but I'm not getting anywhere. I'm new to
VBA and new to programming and need some hints as to where to start. I
thought I needed to do an array, and then a if...then statement, but I can't
get it to work.

Does someone have a hint for me? Point me in the right direction?

Much thanks,
 
D

David M. Marcovitz

First step: How will you code the fact that a particular slide is in
presentation a, b, c, d? Will you just know this (based on your list
below (I assume not because with four slides, you can just copy the
presentation and delete slides, so I'm guessing your four slides was an
example)?

You will need to mark each slide in some way that lets you know that it
is in presentation a, b, c, and/or d. You could have a named text box on
each slide (even off the viewable area of the slide), or you could use
tags, or ...

Once you know how the slide is marked, the VBA should be pretty easy.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
G

Guest

Oops. I think I just posted an answer that did nothing but quote your
question. Still finding my way around this site.

I don't know what tags are; where would I find info on those? Also, how
would one use a "named" text box?

You're right, there are 6 master presentations, all with between 30 and 60
slides each...which is why I didn't want to do the copy and paste thing. What
I HAD been doing was copying the whole presentation and then using vb
assigned to buttons to DELETE the slides that weren't supposed to be there,
but every time a slide is added...well. Can you say, "ICK!"

David, is there a similar solution in your book? If so, I'll hop in the car
and fly to Borders THIS SECOND to get it.
 
G

Guest

David M. Marcovitz said:
First step: How will you code the fact that a particular slide is in
presentation a, b, c, d? Will you just know this (based on your list
below (I assume not because with four slides, you can just copy the
presentation and delete slides, so I'm guessing your four slides was an
example)?

You will need to mark each slide in some way that lets you know that it
is in presentation a, b, c, and/or d. You could have a named text box on
each slide (even off the viewable area of the slide), or you could use
tags, or ...

Once you know how the slide is marked, the VBA should be pretty easy.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
S

Steve Rindsberg

Oops. I think I just posted an answer that did nothing but quote your
question. Still finding my way around this site.

I don't know what tags are; where would I find info on those?

Every presentation, and every slide in a presentation, and every shape on a
slide can have pretty much any number of Tags, which are simply named bits of
text.

A couple examples:

With ActivePresentation.Slides(1)
'Add an "IncludeIn" tag to slide 1
'The value of the tag is "ABD"
.Tags.Add Name:="IncludeIn", Value:="ABD"
End With

With ActivePresentation.Slides(1)
' Display the value of the IncludeIn tag on Slide1
MsgBox .Tags("IncludeIn")
End With

So ... hang on:

Sub AirCodeExampleOnly()
' This asks you which "subgroup" you want to add
' Creates a new presentation
' Adds all the slides from your Master presentation that meet the spec

Dim oNewPres As Presentation
Dim oNewSld As Slide
Dim oMasterPres As Presentation
Dim oMasterSld As Slide
Dim sSlideType As String

sSlideType = InputBox("Which slide type?", "Choose Slide Type")
' what if the input is silly?
If Len(Trim$(sSlideType)) = 0 Then
' canceled. quit
Exit Sub
End If
If Len(Trim$(sSlideType)) > 1 Then
' entered more than one character
Exit Sub
End If

' make sure it's uppercase
sSlideType = UCase$(sSlideType)

' Create a new presentation
Set oNewPres = Presentations.Add

' Open the MasterPresentation (EDIT THIS)
Set oMasterPres = Presentations.Open("c:\temp\test.ppt")

For Each oMasterSld In oMasterPres.Slides
' is there a tag?
If Len(oMasterSld.Tags("IncludeIn")) > 0 Then
' Is the value user entered somewhere in the tag?
If InStr(UCase$(oMasterSld.Tags("IncludeIn")), sSlideType) > 0 Then
oMasterSld.Copy
oNewPres.Slides.Paste
End If
End If
Next ' Master Slide
' close the master presentation
oMasterPres.Close

End Sub

Mess with that then we'll work out how to modify it so it works with all of your
master presentations.

Also, how
would one use a "named" text box?

Tags are more reliable. I'd use them instead.
Shape names will turn round and bite you.
 
G

Guest

Okay, I took your suggestion and I've been trying to get this to work, I've
solved countless errors but each solved error brings a new one and now I'm
just plain stuck. Anyone have a clue what I'm doing wrong here?

Public Sub CommandButton1_Click()
' Open the MasterPresentation
Set oMasterPres =
Presentations.Open("C:\PresentationMaker\employee_promo_master2.ppt")

ActivePresentation.Slides(1).Tags.Add "ABC"
ActivePresentation.Slides(2).Tags.Add "BCD"
ActivePresentation.Slides(3).Tags.Add "D"
ActivePresentation.Slides(4).Tags.Add "ABD"

Dim oNewPres As Presentation
Dim oNewSld As Slide
Dim oMasterPres As Presentation
Dim oMasterSld As Slide
Dim sSlideType As String
' Create a new presentation
Set oNewPres = Presentations.Add
For Each oMasterSld In oMasterPres.Slides
If Len(oMasterSld.Tags("IncludeIn")) = "A" Then
oMasterSld.Copy
oNewPres.Slides.Paste
End If
Next ' Master Slide
' close the master presentation
oMasterPres.Close


Unload PrAud3m

End Sub
 
S

Steve Rindsberg

Okay, I took your suggestion and I've been trying to get this to work, I've
solved countless errors but each solved error brings a new one and now I'm
just plain stuck. Anyone have a clue what I'm doing wrong here?

Public Sub CommandButton1_Click()
' Open the MasterPresentation
Set oMasterPres =
Presentations.Open("C:\PresentationMaker\employee_promo_master2.ppt")

This is the start of the problem:
ActivePresentation.Slides(1).Tags.Add "ABC"
ActivePresentation.Slides(2).Tags.Add "BCD"
ActivePresentation.Slides(3).Tags.Add "D"
ActivePresentation.Slides(4).Tags.Add "ABD"

You've added tags with names but no values, which is pretty much the same thing
as adding no tag at all.

Think of a tag as a stickynote with a name at the top at the data further down
on the sheet. When you want to find the data, you look for the sticky note
with the NAME you want and on it, you'll find the VALUE (data) you're after).

You want the code above to be like:

ActivePresentation.Slides(4).Tags.Add Name:="IncludeIn", Value:= "ABD"
 
G

Guest

yes! That made sense as soon as you said it, and does seem to work.

Now, I'm getting "type mismatch" from

If Len(oMasterSld.Tags("IncludeIn")) = "A" Then

I think it's because "ABC" doesn't actually = "A", yes? So how would I say,
rather than an equal to, but if "IncludeIn" CONTAINS the letter "A"? Or have
I misdiagnosed the problem?
 
S

Steve Rindsberg

yes! That made sense as soon as you said it, and does seem to work.

Now, I'm getting "type mismatch" from

If Len(oMasterSld.Tags("IncludeIn")) = "A" Then

I think it's because "ABC" doesn't actually = "A", yes?

Close: it's because Len returns the Length of a string, as a number, whereas
"A" is a string. Different type, so you get Type Mismatch errors.
So how would I say,
rather than an equal to, but if "IncludeIn" CONTAINS the letter "A"? Or have
I misdiagnosed the problem?

If Instr(oMasterSld.Tags("IncludeIn"),"A") > 0 Then


Instr tells you at what position the second string occurs in the first or
returns 0 if it doesn't occur at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top