Question : Powerpoint VBA Find Text in Shape

Experts:

The code below works just fine when the string I'm searching for using the Find Method returns a hit.  It's when there isn't text in the shape that the code errors out on me giving me the following message:
"Run-time error '91'; Object variable or With Block variable not set"

I've tried using If Then statements like if ISIERROR(...) or ISNULL(...) but that doesn't seem to work...

Peter
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Sub UpdateNoteDates() 
Dim sld As Slide
Dim findStr As String
Dim chgStr As String
Dim mvLen As Integer
Dim inFind As String
Dim searchSTring As String
Dim txtRange As TextRange
Dim shp As Shape 
inFind = InputBox("Enter M/D here to change")
mvLen = Len(inFind)
findStr = "Updated: " & inFind
chgStr = InputBox("Input M/D") 
ActiveWindow.ViewType = ppViewNotesPage 
For Each sld In ActivePresentation.Slides
        ActiveWindow.Selection.SlideRange.Shapes("Rectangle 3").Select
        ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Find(findStr).Characters(Start:=10, Length:=mvLen).Select
            With ActiveWindow.Selection.TextRange
                .Text = chgStr
            End With
Next 
ActiveWindow.ViewType = ppViewNormal 
End Sub

Answer : Powerpoint VBA Find Text in Shape

Hi,

try using a variable for the Find, then test for success by testing for the variable Not being Nothing

somethling like this

Cheers

Dave

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
Sub UpdateNoteDates()
    Dim sld As Slide
    Dim findStr As String
    Dim chgStr As String
    Dim mvLen As Integer
    Dim inFind As String
    Dim searchSTring As String
    Dim txtRange As TextRange
    Dim shp As Shape
    inFind = InputBox("Enter M/D here to change")
    mvLen = Len(inFind)
    findStr = "Updated: " & inFind
    chgStr = InputBox("Input M/D")
    Dim Fnd
    ActiveWindow.ViewType = ppViewNotesPage
    For Each sld In ActivePresentation.Slides
        ActiveWindow.Selection.SlideRange.Shapes("Rectangle 3").Select
        Set Fnd = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Find(findStr)
        If Not Fnd Is Nothing Then
            With Fnd.Characters(Start:=10, Length:=mvLen)
                .Text = chgStr
            End With
        End With
    Next
    ActiveWindow.ViewType = ppViewNormal
End Sub
Random Solutions  
 
programming4us programming4us