L
lvcha.gouqizi
Hi Tom,
I got your help in locating shapes in VBA. I need to return the located
shape so I modified it into a function. But whenver I step into this
line "findOval = shp", it just jumps out of the function without
returning any shape. Do you have any suggestions? Thanks.
This is your original code:
Sub DD()
Dim shp As Shape
Dim s As String
Dim TargetText As String
TargetText = "dog"
For Each shp In ActiveSheet.Shapes
On Error Resume Next
s = ""
s = shp.TextFrame.Characters.Text
On Error GoTo 0
If InStr(1, s, TargetText, vbTextCompare) Then
shp.Select
Exit For
End If
Next
End Sub
And this is what I modified:
Function findOval(TargetText As String)
Dim shp As Shape
Dim s As String
For Each shp In ActiveSheet.Shapes
On Error Resume Next
s = ""
s = shp.TextFrame.Characters.Text
On Error GoTo 0
If InStr(1, s, TargetText, vbTextCompare) Then
shp.Select
findOval = shp
Exit For
End If
Next
End Function
I got your help in locating shapes in VBA. I need to return the located
shape so I modified it into a function. But whenver I step into this
line "findOval = shp", it just jumps out of the function without
returning any shape. Do you have any suggestions? Thanks.
This is your original code:
Sub DD()
Dim shp As Shape
Dim s As String
Dim TargetText As String
TargetText = "dog"
For Each shp In ActiveSheet.Shapes
On Error Resume Next
s = ""
s = shp.TextFrame.Characters.Text
On Error GoTo 0
If InStr(1, s, TargetText, vbTextCompare) Then
shp.Select
Exit For
End If
Next
End Sub
And this is what I modified:
Function findOval(TargetText As String)
Dim shp As Shape
Dim s As String
For Each shp In ActiveSheet.Shapes
On Error Resume Next
s = ""
s = shp.TextFrame.Characters.Text
On Error GoTo 0
If InStr(1, s, TargetText, vbTextCompare) Then
shp.Select
findOval = shp
Exit For
End If
Next
End Function