0
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) = "" Then
    MsgBox "Nothing entered"
    Exit Sub
End If
Set rStart = ActiveCell
For Each shp In ActiveSheet.Shapes
    sTemp = shp.TextFrame.Characters.Text
    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
Next
MsgBox "No more found"
rStart.Select
Set rStart = Nothing
End Sub

你好,

我制作了上面的宏,用于在“拥挤”的工作表中查找 excel 形状,通过里面写的文本。该宏适用于任何新书,但不适用于我需要的书,它是否继续显示以下消息:

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

一旦我单击“调试”,它就会突出显示该行:

sTemp = shp.TextFrame.Characters.Text

怎么了?

感谢您的帮助基亚拉

4

3 回答 3

2

很抱歉打破惯例,但我得到了类似的错误:

The specified value is out of range
Run-time error -2147024809

在我的场景中,我只是在存储形状对象的类中将形状作为 GET 属性的一部分返回。该属性适用于形状类型文本框,但在发送回线条形状时会出错。如下所示。我不能使用 on 错误,或者不知道如何因为错误发生在 End Property?

Public Property Get shp_Obj() As Shape
    If prvt_int_Ordinal = 13 Them

        MsgBox prvt_Shp_Shape.Name, , "prvt_Shp_Shape.Name"



    Set shp_Obj = prvt_Shp_Shape
   End If

End Property
于 2014-09-21T17:21:27.283 回答
1

您的代码没有任何问题。如果活动工作表受密码保护,您只会收到此错误。

你能检查一下吗?

还要检查下面的网址

Excel 宏“运行时错误 '1004”

于 2013-09-10T10:10:26.223 回答
1

我认为由于无法检查形状中是否存在TextFrame,因此您应该使用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

`

于 2013-09-10T10:26:52.927 回答