Run-Time error '1004' The specified value is out of range

后端 未结 3 1297
情深已故
情深已故 2021-01-28 02:27
Sub FindInShapes1()   
Dim rStart As Range
Dim shp As Shape
Dim sFind As String
Dim sTemp As String
Dim Response

sFind = InputBox(\"Search for?\")
If Trim(sFind) = \"\"         


        
3条回答
  •  终归单人心
    2021-01-28 03:28

    I think as there is no way to check for the existence of a TextFrame within a shape, you should ignore the error by using On Error Resume Next:

    Sub FindInShapes1()
    Dim rStart As Range
    Dim shp As Shape
    Dim sFind As String
    Dim sTemp As String
    Dim Response
    
    On Error Resume Next
    
    sFind = InputBox("Search for?")
    If Trim(sFind) = "" Then
        MsgBox "Nothing entered"
        Exit Sub
        End If
        Set rStart = ActiveCell
        For Each shp In ActiveSheet.Shapes
            'If shp.TextFrame.Characters.Count > 0 Then
            If InStr(LCase(sTemp), LCase(sFind)) <> 0 Then
                shp.Select
                Response = MsgBox( _
                    prompt:=shp.TopLeftCell & vbCrLf & _
                    sTemp & vbCrLf & vbCrLf & _
                    "Do you want to continue?", _
                    Buttons:=vbYesNo, Title:="Continue?")
                If Response <> vbYes Then
                    Set rStart = Nothing
                    Exit Sub
                End If
            End If
            'End If
            sTemp = shp.TextFrame.Characters.Text
    
        Next
        MsgBox "No more found"
        rStart.Select
        Set rStart = Nothing
    End Sub
    

    `

提交回复
热议问题