Auto-populating textboxes with random text phrases from a list

  • Thread starter Thread starter Max
  • Start date Start date
M

Max

Hi guys,

PPT97 question (in one breath .. ).

Is there a way to programmatically populate textboxes or autoshapes
which are all to be identically placed at say, the top right corner
of every slide (except title slides) in a presentation
with one-liner text phrases taken at random from a list of phrases
in either excel 97, a table in word97 or even say, from another textbox in a
ppt97 slide itself ?

The random one-liners on each slide are intended
to add some light humour / variety to "spice" up the presentation.

Any insights?

Thanks in advance.
 
Is there a way to programmatically populate textboxes or autoshapes
which are all to be identically placed at say, the top right corner
of every slide (except title slides) in a presentation
with one-liner text phrases taken at random from a list of phrases
in either excel 97, a table in word97 or even say, from another textbox in a
ppt97 slide itself ?

It's certainly possible; are you looking for an outline of how to program it
yourself or an existing addin? I haven't heard of anything like this in the
wild.
 
Steve, thanks for response.

I'm game for either option, albeit it'll be easier for me
if existing add-ins or vba subs are available.
.. I haven't heard of anything like this in the wild.
there's always a first time? for everything <g>
 
Steve, thanks for response.

I'm game for either option, albeit it'll be easier for me
if existing add-ins or vba subs are available.

there's always a first time? for everything <g>

You just never know when something might tickle someones fancy. For example, this might
happen:

Save your presentation to a folder of your choice.
Create or copy a text file of phrases into that folder. It must be a plain ascii text file
(something Notepad can read, for example) and it must be named PHRASES.TXT. It should have
one phrase per line.

Add a new module in the VBA editor and paste in the code below.
Edit PlacePhrases as needed to alter the text formatting.
Run PlacePhrases to put a phrase from your text file on every slide (except title slides) in
the presentation
The phrases will be chosen at random, but you can alter GetPhrase to change this.
Run DeletePhrases to remove all the phrases added by PlacePhrases

''' CODE STARTS HERE -- COPY AND PASTE EVERYTHING BELOW BUT NOT INCLUDING THIS LINE

Public rayPhrases() As String

Sub PlacePhrases()
' Puts a phrase in the same position on every slide in a presentation
' Excludes title slides

Dim oSl As Slide
Dim oText As Shape
ReDim rayPhrases(1 To 1) As String
' Load an array of phrases to use
Call InitPhrases
For Each oSl In ActivePresentation.Slides
' Skip Title slides
If Not oSl.Layout = ppLayoutTitle Then
' Add the textbox
Set oText = oSl.Shapes.AddTextbox(msoTextOrientationHorizontal, 0#, 0#, 100#,
24#)
' Add text and format it
With oText.TextFrame
.WordWrap = msoFalse
With .TextRange
' GetPhrase should return the next phrase to be used
.Text = GetPhrase
With .Font
.Name = "Arial"
.Size = 24
.Bold = msoFalse
' whatever other defaults you like here
.Color.RGB = RGB(255, 0, 0) ' Red
End With
End With
End With
' Tag it so we can find and remove it later
Call oText.Tags.Add("PHRASE", "PHRASE")
End If
Next oSl
End Sub

Function GetPhrase() As String
' Returns a random phrase from the array of phrases

Dim lTodaysPhrase As Long ' index into array of phrases

lTodaysPhrase = Int((UBound(rayPhrases) - LBound(rayPhrases) + 1) _
* Rnd + LBound(rayPhrases))
GetPhrase = rayPhrases(lTodaysPhrase)

End Function
Sub InitPhrases()
' Loads array of phrases - rewrite to suit your needs
' This version uses a file of phrases in the same folder as current presentation
' Filename = PHRASES.TXT
' ASCII file, one phrase per line

Dim PhraseFile As String
Dim FileNum As Integer
Dim Buffer As String
PhraseFile = ActivePresentation.Path & "\" & "PHRASES.TXT"

FileNum = FreeFile()
Open PhraseFile For Input As FreeFile
While Not EOF(FileNum)
Line Input #FileNum, Buffer
Call AddAPhrase(rayPhrases, Buffer)
Wend
Close #FileNum

' This leaves the array with one bogus empty record at end so
ReDim Preserve rayPhrases(1 To UBound(rayPhrases) - 1) As String

End Sub

Sub AddAPhrase(Phrases As Variant, Phrase As String)
' adds a new phrase to the array
Phrases(UBound(Phrases)) = Phrase
ReDim Preserve Phrases(1 To UBound(Phrases) + 1) As String
End Sub

Sub DeletePhrases()
' deletes all the phrases we added

Dim oSl As Slide
Dim oSh As Shape
Dim X As Long
For Each oSl In ActivePresentation.Slides
For X = oSl.Shapes.Count To 1 Step -1
If oSl.Shapes(X).Tags("PHRASE") = "PHRASE" Then
oSl.Shapes(X).Delete
End If
Next X
Next oSl

End Sub
 
Steve Rindsberg said:
You just never know when something might tickle someones fancy.
For example, this might happen: ....

Brilliant !! Simply superb.
Runs like magic.
Yeah, that's what it is, simply stated <g>

Many thanks, Steve.
 
Brilliant !! Simply superb.
Runs like magic.
Yeah, that's what it is, simply stated <g>

A ticklish fancy is a terrible thing to waste. ;-)
Note that the random choice version will probably work best with a lot of
different quotes (less likely to land on the same one on adjacent slides the
way it does with only a few quotes).
 
Steve Rindsberg said:
... A ticklish fancy is a terrible thing to waste. ;-)
Note that the random choice version will probably work best with a lot of
different quotes (less likely to land on the same one on adjacent slides the
way it does with only a few quotes).

Yes, but only a minor issue.
I've got no problems with that.
[I've got tons of quotes / witty one-liners <g>]

Terrific job, Steve ! Thanks again.
 
Back
Top