PDA

View Full Version : [SOLVED:] Change Placeholder text from "Internal Use" to "Confidential"



RogChele
11-27-2016, 04:59 PM
I was given a presentation with a slide master that has been formatted to their specification. Since I am new to VBA in powerpoint, I have been struggling with a particular task.

Goal:

- create a macro that changes the current text placeholder to "Internal use" in the footer of the powerpoint in the Slide Master.
The actual "footer" is used for title of the presentation so I will assume that the box I am trying to change is the placeholder?

- once the text has been changed, I would like to modify the font, font size, and color.


- Next macro I am trying to create, searches for the placeholder with "Internal Use" and replaces it with "Strictly Confidential" .

- once the new text has been inserted, I want to modify the font color.

- I need the ability to run a macro that will allow me to constantly change back and forth from "Internal Use" to "Confidential" based on the audience.

- with this change it needs to be reflected in the actual presentation slides.


Problem:

- I have google for solutions and I am having a hard time specifying if the current "Internal Use" text is a textbox or placeholder.
- I have written the code to name the "box" as a footer and as a placeholder (not sure what I am doing wrong)

- I at one point figured out a way to make the text change in the slide master but it did not impact the actual presentation (and I need it to)

- I have attempted to add a text placeholder (onthe master slide) but that area of the powerpoint is greyed out.



1st Attempt:
Below is a copy of a code I was assisted with but my problem is its referencing slides when I believe I need to reference the slide master? And lastly, I believe they are trying to take the "Internal Use" and change it to "Confidential" in the same macro and its not working.

Sub footers()
Dim osld As Slide
Dim oCust As CustomLayout
'change this to the text needed
Const strFooter1 As String = "abc"
Const strFooter2 As String = "xyz"
'change master
With ActivePresentation.SlideMaster.HeadersFooters.Footer
Select Case .Text
Case strFooter2
.Text = strFooter1
Case strFooter1
.Text = strFooter2
End Select
End With
'change layouts
For Each oCust In ActivePresentation.SlideMaster.CustomLayouts
With oCust.HeadersFooters.Footer
Select Case .Text
Case strFooter2
.Text = strFooter1
Case strFooter1
.Text = strFooter2
End Select
End With
Next oCust
'change slides
For Each osld In ActivePresentation.Slides
With osld.HeadersFooters.Footer
.Visible = True
Select Case .Text
Case strFooter2
.Text = strFooter1
Case strFooter1
.Text = strFooter2
End Select
End With
Next osld
End Sub



2nd Attempt (found help online)
Sub My_Internal()
Dim oCust As CustomLayout
Dim oColl As New Collection
Dim oDes As Design
Dim oShp As Shape
Dim osld As Slide

ActivePresentation.SlideMaster.HeadersFooters.Footer.Visible = True
'create collection of footers in master and all layouts
'######################################################
For Each oDes In ActivePresentation.Designs
For Each oShp In oDes.SlideMaster.Shapes
If oShp.Type = msoPlaceholder Then
If oShp.PlaceholderFormat.Type = ppPlaceholderFooter Then
oColl.Add oShp
End If
End If
Next oShp
For Each oCust In oDes.SlideMaster.CustomLayouts
oCust.HeadersFooters.Footer.Visible = True
For Each oShp In oCust.Shapes
If oShp.Type = msoPlaceholder Then
If oShp.PlaceholderFormat.Type = ppPlaceholderFooter Then
oColl.Add oShp
End If
End If
Next oShp
Next oCust
Next oDes
'######################################################
'set the footers
For Each oShp In oColl
With oShp.TextFrame.TextRange
.Text = "Strictly Confidential"
With .Font
.Name = "Arial"
.Size = 8
.Color.RGB = RGB(209, 0, 36)
End With
End With
Next oShp

For Each osld In ActivePresentation.Slides
With osld.HeadersFooters.Footer
.Visible = True
Select Case .Text
Case strFooter2
.Text = strFooter1
Case strFooter1
.Text = strFooter2
End Select
End With
Next osld
End Sub




All help is GREATLY appreciated. I have been working on this for several days and I am at a loss.

Thank you,

RogChele

John Wilson
11-28-2016, 06:15 AM
Try this:


Sub FooterFix()
Dim osld As Slide
Dim ofoot As Shape
Dim ocust As CustomLayout
Dim strfoot As String
For Each osld In ActivePresentation.Slides
osld.HeadersFooters.Footer.Visible = True
Set ofoot = getFooter(osld)
Select Case UCase(ofoot.TextFrame2.TextRange)
Case Is = "INTERNAL USE", ""
strfoot = "Confidential"
Case Is = "CONFIDENTIAL"
strfoot = "Internal Use"
End Select
Call addText(ofoot, strfoot)
Next osld
For Each ocust In ActivePresentation.Designs(1).SlideMaster.CustomLayouts
Set ofoot = getFooter(ocust)
Call addText(ofoot, strfoot)
Next ocust
Set ofoot = getFooter(ActivePresentation.Designs(1).SlideMaster)
Call addText(ofoot, strfoot)
End Sub


Function getFooter(obj As Object) As Shape
For Each getFooter In obj.Shapes
If getFooter.Type = msoPlaceholder Then
If getFooter.PlaceholderFormat.Type = ppPlaceholderFooter Then Exit Function
End If
Next
End Function


Sub addText(ofoot As Shape, strfoot As String)
With ofoot.TextFrame2.TextRange
.Text = strfoot
.Font.Fill.ForeColor.RGB = RGB(209, 0, 36)
.Font.Name = "Arial"
.Font.Size = 8
End With
End Sub

RogChele
11-28-2016, 08:37 AM
Of the following code, it gave me a runtime 91 error message on the line in quotes:
"Select Case UCase(ofoot.TextFrame2.TextRange)"

Error Message:
ofoot.textframe2.textrange = <Object variable or With block variable not set>

but the object variable "ofoot" has already been referenced

Joy RogChele

John Wilson
11-28-2016, 10:22 AM
You would get that error if the slide / master did not have a footer placeholder


Sub FooterFix()
Dim osld As Slide
Dim ofoot As Shape
Dim ocust As CustomLayout
Dim strfoot As String
For Each osld In ActivePresentation.Slides
osld.HeadersFooters.Footer.Visible = True
Set ofoot = getFooter(osld)
If Not ofoot Is Nothing Then
Select Case UCase(ofoot.TextFrame2.TextRange)
Case Is = "INTERNAL USE", ""
strfoot = "Confidential"
Case Is = "CONFIDENTIAL"
strfoot = "Internal Use"
End Select
Call addText(ofoot, strfoot)
End If
Next osld
For Each ocust In ActivePresentation.Designs(1).SlideMaster.CustomLayouts
Set ofoot = getFooter(ocust)
If Not ofoot Is Nothing Then Call addText(ofoot, strfoot)
Next ocust
Set ofoot = getFooter(ActivePresentation.Designs(1).SlideMaster)
If Not ofoot Is Nothing Then Call addText(ofoot, strfoot)
End Sub


Function getFooter(obj As Object) As Shape
For Each getFooter In obj.Shapes
If getFooter.Type = msoPlaceholder Then
If getFooter.PlaceholderFormat.Type = ppPlaceholderFooter Then Exit Function
End If
Next
End Function


Sub addText(ofoot As Shape, strfoot As String)
With ofoot.TextFrame2.TextRange
.Text = strfoot
.Font.Fill.ForeColor.RGB = RGB(209, 0, 36)
.Font.Name = "Arial"
.Font.Size = 8
End With
End Sub




Also if you have a very early version TextFrame2 will cause an error. Say which version you have

RogChele
11-28-2016, 10:55 AM
I have PowerPoint 2016 and I checked the Master Layout and Footer was not checked.
I checked the Footer and then inserted the "Internal Use" and saved.
When I ran the code, it deleted "Internal Use" and now just says Footer.

If the Footer box was not checked in the master layout, does that mean the text in the footer layouts are textboxes/created placeholders?


Deep Desire to Learn,
Thank you,

Joy RogChele

John Wilson
11-28-2016, 02:07 PM
Probably. You would need to post a presentation to be sure. Are you able to edit the footers on the actual slides? Another possibility is it was originally created in version 2003 or earlier which has a different footer method.

If you can post a few slides somewhere it will help.

RogChele
11-29-2016, 09:40 AM
I checked and the powerpoint was originally created in 2013 and I am using 2016 version (problem 1)
The "Internal Use" text was just text, not a footer, not a placeholder, and not a textbox (problem 2)

I have now created a textbox (textbox1) through the developer tab. I entered the name through the properties option.
If I try to edit the code above, instead of SUB it revises to PRIVATE SUB

I am now getting a Compile Error - which I know is because I tried to Dim Box as Textbox1 (tried it as shape, still not working)

It is where you would have had ofoot as Shape.


Private Sub TxtFoot_Change()
Dim Textbox1 As Shape
Dim sld As Slide
Dim StrText As String
Dim ocust As CustomLayout
For Each sld In ActivePresentation.SlideMaster
sld.Master.Textbox1.Visible = True
Set Box = getFooter(sld)
If Not Box Is Nothing Then
Select Case UCase(Textbox1.TextFrame2.TextRange)
Case Is = "FOR INTERNAL USE ONLY", ""
strfoot = "Confidential"
Case Is = "CONFIDENTIAL"
strfoot = "For Internal Use Only"
End Select
Call addText(Box, strfoot)
End If
Next sld
For Each ocust In ActivePresentation.Designs(1).SlideMaster.CustomLayouts
Set Box = getFooter(ocust)
If Not Box Is Nothing Then Call addText(Box, strfoot)
Next ocust
Set Box = getFooter(ActivePresentation.Designs(1).SlideMaster)
If Not Box Is Nothing Then Call addText(Box, strfoot)
End Sub

Function getFooter(obj As Object) As Shape
For Each getFooter In obj.Shapes
If getFooter.Type = msoPlaceholder Then
If getFooter.PlaceholderFormat.Type = ppPlaceholderFooter Then Exit Function
End If
Next
End Function


Sub addText(Box As Shape, strfoot As String)
With Box.TextFrame2.TextRange
.Text = strfoot
.Font.Fill.ForeColor.RGB = RGB(209, 0, 36)
.Font.Name = "Arial"
.Font.Size = 8
End With
End Sub

John Wilson
11-30-2016, 07:29 AM
This is not meant to be judgemental but you are just creating problems for yourself. It is much harder to work with activX textboxes and you are going to struggle with your level of knowledge. Post a slide or two somewhere. If you use the advanced tab you can attach a sample here. If they really used an ActivX textbox (which is not smart) the code will be quite different.

RogChele
11-30-2016, 08:59 AM
You are far from being judgemental!! :) I know I am VERY new at this and I am grasping some of the concepts but still run into issues (clearly).

I have only been studying/learning how to do this for 1.5 weeks - I am more than appreciative for any feedback, criticism, helpful hints that I recieve.

I have attached a template powerpoint that I have been testing on so I would not ruin the final project.

The "cut off textbox" if what I created and yes it is ActiveX Control - and clearly that is bad lol (googling why now)

Thank you for your patience and willingness to help me learn!

John Wilson
11-30-2016, 09:27 AM
Try this:


Sub Updater()


Dim ActiShape As Object
' be sure to get the name exactly correct
Set ActiShape = ActivePresentation.Designs(1).SlideMaster.Shapes("TextBox1").OLEFormat.Object
Select Case ActiShape.Text
Case Is = "For Internal Use Only"
ActiShape.Text = "Confidential"
Case Is = "Confidential", ""
ActiShape.Text = "For Internal Use Only"
End Select
End Sub

John Wilson
11-30-2016, 09:36 AM
Try this: (with colour)


Sub Updater()Dim ActiShape As Object
' be sure to get the name exactly correct
Set ActiShape = ActivePresentation.Designs(1).SlideMaster.Shapes("TextBox1").OLEFormat.Object
ActiShape.ForeColor = &H2400D1
'this is the color you mentioned in HEX!
Select Case ActiShape.Text
Case Is = "For Internal Use Only"
ActiShape.Text = "Confidential"
Case Is = "Confidential", ""
ActiShape.Text = "For Internal Use Only"
End Select
End Sub

RogChele
11-30-2016, 10:38 AM
I revised the code below in an attempt to have the color of the text change based on the text itself.

Strictly Confidential would be "&H2400D1"
For Internal Use Only would be "&H808080"

The font portion of the code works but not the name and forecolor portion.


Sub Updater()
Dim ActiShape As Object
' be sure to get the name exactly correct
Set ActiShape = ActivePresentation.Designs(1).SlideMaster.Shapes("TextBox1").OLEFormat.Object

'ActiShape.ForeColor = &H2400D1
'this is the color you mentioned in HEX!
Select Case ActiShape.Text
Case Is = "For Internal Use Only"
ActiShape.Text = "Confidential"
Case Is = "Confidential", ""
ActiShape.Text = "For Internal Use Only"
End Select

With ActiShape
.Text = "For Internal Use Only"
With .Font
.Name = "Arial"
.Size = 9
.ForeColor = &H808080
End With
End With

With ActiShape
.Text = "Strictly Confidential"
With .Font
.Name = "Arial"
.Size = 9
.ForeColor = &H2400D1
End With
End With
End Sub

John Wilson
11-30-2016, 02:14 PM
Maybe this:


Sub Updater()
Dim ActiShape As Object
' be sure to get the name exactly correct
Set ActiShape = ActivePresentation.Designs(1).SlideMaster.Shapes("TextBox1").OLEFormat.Object
ActiShape.Font.Name = "Arial"
ActiShape.Font.Size = 8
'this is the color you mentioned in HEX!
Select Case ActiShape.Text
Case Is = "For Internal Use Only"
ActiShape.Text = "Confidential"
ActiShape.ForeColor = &H2400D1
Case Is = "Confidential", ""
ActiShape.Text = "For Internal Use Only"
ActiShape.ForeColor = &H2808080
End Select
End Sub

RogChele
11-30-2016, 02:46 PM
John,

Thank you SO much. The code worked and I've revised it to include font variables such as Bold, Italicize, etc and it still works.

Thank you again for your patience at my naivete and for all of your help!!!

Last question for you.

What is the most efficient way to learn VBA programming?

Right now I have the Excel Bible as well as VBA for Dummies (Excel) because that is where my learning is focused (and I could not find anythign on Powerpoint specifically)

I of course, test things out, fail, try again, google. etc.

Any advise is appreciated.

Joy

John Wilson
12-01-2016, 12:00 AM
There is a PPT vba book "Powerful PowerPoint for Educators" by David Marcovitz.

David is a friend and the book is useful especially for beginners.

The only way to get in depth info is to study other code from experts and try to work out how it works. PowerPoint code is very different to Excel code.

Places to look for good code

http://www.pptalchemy.co.uk/powerpoint_hints_and_tips_tutorials.html (that's me)
www.pptfaq.com (http://www.pptfaq.com) Steve Rindsberg (he was my mentor!) Scroll to Programming
http://skp.mvps.org/vba.htm#.WD_KOtWLS70 Shyam Pillai good for adnced topics