Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General PowerPoint Questions / June 2006

Tip: Looking for answers? Try searching our database.

code to find colon in text placeholder?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Geoff Cox - 08 Jun 2006 07:24 GMT
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
Geoff Cox - 08 Jun 2006 07:58 GMT
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
John Wilson - 08 Jun 2006 09:06 GMT
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
Signature

-----------------------------------------
Did that answer the question / help?
_____________________________
John Wilson
Microsoft Certified Office Specialist

> 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
[quoted text clipped - 44 lines]
>
> End Sub
Geoff Cox - 08 Jun 2006 11:54 GMT
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
John Wilson - 08 Jun 2006 14:09 GMT
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
Signature

-----------------------------------------
Did that answer the question / help?
_____________________________
John Wilson
Microsoft Certified Office Specialist

> John,
>
[quoted text clipped - 47 lines]
>
> End Sub
David M. Marcovitz - 08 Jun 2006 14:13 GMT
> If oShp.Type = 14 Then

What about:

If oShp.Type = 14 And oShp.HasTextFrame Then

--David

Signature

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/

John Wilson - 08 Jun 2006 14:51 GMT
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.
Signature

-----------------------------------------
Did that answer the question / help?
_____________________________
John Wilson
Microsoft Certified Office Specialist

> John,
>
[quoted text clipped - 47 lines]
>
> End Sub
Geoff Cox - 08 Jun 2006 13:47 GMT
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
Steve Rindsberg - 08 Jun 2006 15:22 GMT
Note that you can simplify this:

>         strtext = oShp.TextFrame.TextRange
>        
[quoted text clipped - 4 lines]
>             Next c
>         End If

to

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

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
John Wilson - 08 Jun 2006 16:21 GMT
Thanks Steve - stored in "lessons learned today" box!!!

_____________________________
John

> Note that you can simplify this:
>
[quoted text clipped - 18 lines]
> PPTools:  www.pptools.com
> ================================================
Steve Rindsberg - 08 Jun 2006 20:42 GMT
> 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.  

> _____________________________
> John
[quoted text clipped - 21 lines]
> > PPTools:  www.pptools.com
> > ================================================

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================
Geoff Cox - 09 Jun 2006 08:21 GMT
>Note that you can simplify this:
>
[quoted text clipped - 12 lines]
>   ' the text has been colonized
>End If

Thanks to you Steve and everyone else!

Cheers

Geoff

>-----------------------------------------
>Steve Rindsberg, PPT MVP
>PPT FAQ:  www.pptfaq.com
>PPTools:  www.pptools.com
>================================================
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.