code to find colon in text placeholder?

G

Geoff Cox

Hello,

I am trying to search multiple ppt files to find a few cases where
there is a colon in a text placeholder (type 14). I would like to be
able to view the slides which have the colon.

Can anyone please point me at macro code which tackles this kind of
action?

The code below will find an action button on any slide - perhaps this
could be changed to find the colon??

I am not clear how the

If .Shapes.Count > 0 Then

would be changed to cope with looking for a colon within a text
placeholder ....

Thanks

Geoff


Sub MyMacro(strMyFile As String)
' this gets called once for each file that meets the spec you enter in
ForEachPresentation
' strMyFile is set to the file name each time

' Probably at a minimum, you'd want to:
Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

With oPresentation


Dim oSh As shape
Dim bFoundButton As Boolean
Dim bFoundRectangle As Boolean

bFoundButton = False ' to start

With ActivePresentation.Slides(ActivePresentation.Slides.Count)

If .Shapes.Count > 0 Then

For Each oSh In _
ActivePresentation.Slides(ActivePresentation.Slides.Count) _
.Shapes
If oSh.Type = 1 Then
If oSh.AutoShapeType = 130 Then
bFoundButton = True
End If
End If
Next

' Now display a message
' If bFoundButton Then
' MsgBox "Found a Forward or Next button on the last slide"
'Else
' MsgBox "No Forward/Next buttons here"
'End If

If Not bFoundButton Then
MsgBox "No button on last slide of " & strMyFile
End If

Else
MsgBox "No shape on this last slide in " & strMyFile
End If

End With

oPresentation.Close


End With
Set oSh = Nothing
Set oPresentation = Nothing

End Sub
 
G

Geoff Cox

On Thu, 08 Jun 2006 07:24:55 +0100, Geoff Cox


trying to make a little head way myself I have following code which
does find and select text placeholders but then comes up with an error
message re Shape (unknown member) and "to select a shape its view must
be active". How do I make it active?

Also how do I search for the colon within the text placeholder?

Geoff


Sub MyMacro(strMyFile As String)

Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

With oPresentation

Dim oSl As Slide
Dim foundTextPlaceHolder As Boolean
foundTextPlaceHolder = False


For Each oSl In ActivePresentation.Slides

Dim oSh As shape
'On Error GoTo ErrorHandler

For Each oSh In oSl.Shapes

If oSh.Type = 14 Then

oSh.Select

foundTextPlaceHolder = True
MsgBox "text placeholder found in " & strMyFile

End If

Next oSh

Next oSl

oPresentation.Close

End With
Set oSh = Nothing
Set oPresentation = Nothing

End Sub
 
G

Guest

Geoff

If shapes.count > 0
This just checks that there are some shapes on the slide.

Try this code and see if its what you need ( or maybe use it as a starting
point)

Checks all shapes on all slides > Is it a type 14 shape? If yes checks text
for a colon and reports each slide number with colons in turn.
'code starts
Sub Findcolon()

Dim oSld As Slide
Dim oShp As Shape
Dim strtext As String
Dim strchr As String

For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.Type = 14 Then
strtext = oShp.TextFrame.TextRange
For c = 1 To Len(strtext)
strchr = Mid$(strtext, c, 1)
If strchr = ":" Then MsgBox ("found on slide " & oSld.SlideNumber)
Next c
End If
Next oShp
Next oSld
End Sub
'code ends
--
 
G

Geoff Cox

John,

Thanks for your code ideas - I have tried following but get a runtime
error message,

TextFrame(unknown member): Invalid request. This type of shape cannot
have a TextRange.

Debug points at

strtext = sHp.TextFrame.TextRange

Any thoughts?!

Cheers

Geoff

Sub MyMacro(strMyFile As String)

Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

With oPresentation

Dim oSld As Slide
Dim oShp As shape
Dim strtext As String
Dim strchr As String

For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.Type = 14 Then
strtext = oShp.TextFrame.TextRange
For c = 1 To Len(strtext)
strchr = Mid$(strtext, c, 1)
If strchr = ":" Then MsgBox ("found on slide " & _
oSld.SlideNumber)
Next c
End If
Next oShp
Next oSld

oPresentation.Close


Set oSh = Nothing
Set oPresentation = Nothing

End With

End Sub
 
G

Geoff Cox

John,

Have found that the error message can be avoided using " On Error
Resume Next" etc.

Cheers

Geoff





For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.Type = 14 Then

On Error Resume Next

strtext = oShp.TextFrame.TextRange

For c = 1 To Len(strtext)
strchr = Mid$(strtext, c, 1)
If strchr = ":" Then MsgBox ("found on slide " &
oSld.SlideNumber & " in " & strMyFile)
Next c
End If

On Error GoTo 0

Next oShp
Next oSld
 
G

Guest

Debug points at
"strtext = sHp.TextFrame.TextRange "
Note this isnt what my code said!

If this is just a spelling mistake you could maybe try this ammendment

Sub findcolons()
Dim oSld As Slide
Dim oShp As Shape
Dim strtext As String
Dim strchr As String

For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.Type = msoPlaceholder Then
strtext = oShp.TextFrame.TextRange
For c = 1 To Len(strtext)
strchr = Mid$(strtext, c, 1)
If strchr = ":" Then MsgBox ("found on slide " & oSld.SlideNumber)
Next c
End If
End If
Next oShp
Next oSld
End Sub
--
 
G

Guest

Both these do pretty well the same job (though DM's is neater!)

The problem is that type 14 shapes include placeholders that cannot have a
text frame (eg picture holders), I guess your presentation had such a
placeholder which would cause the error.
--
 
S

Steve Rindsberg

Note that you can simplify this:
strtext = oShp.TextFrame.TextRange

For c = 1 To Len(strtext)
strchr = Mid$(strtext, c, 1)
If strchr = ":" Then MsgBox ("found on slide " &
oSld.SlideNumber & " in " & strMyFile)
Next c
End If

to

If Instr(oShp.TextFrame.TextRange,":") > 0 Then
' the text has been colonized
End If
 
G

Guest

Thanks Steve - stored in "lessons learned today" box!!!

_____________________________
John
 
S

Steve Rindsberg

John Wilson said:
Thanks Steve - stored in "lessons learned today" box!!!

I had my WWSD t-shirt on. On the back it says "What would Shyam do?" ;-)

OBTW, good call on the placeholders that can't have text frames. There's also
a bug in PPT97 - if you drag a picture into a text placeholder, the placeholder
when queried by VB says "Yes. I have a text frame." but errors when you ask
for the text.
 
G

Geoff Cox

Note that you can simplify this:


to

If Instr(oShp.TextFrame.TextRange,":") > 0 Then
' the text has been colonized
End If

Thanks to you Steve and everyone else!

Cheers

Geoff
 

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