繁体   English   中英

运行时错误'1004'指定的值超出范围

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

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

嗨,

我编写了上面的Macro,以便在其中写的文本中找到“经过欺骗的”工作表中的excel形状。 如果它继续显示以下消息,则该宏可用于任何新书,但不适用于我需要的书:

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

当我单击“调试”时,它将突出显示以下行:

sTemp = shp.TextFrame.Characters.Text

怎么了?

感谢您的帮助Chiara

您的代码没有错。 如果活动工作表受密码保护,则只会出现此错误。

你能检查一下吗?

另外从下面检查网址

Excel宏“运行时错误'1004”

我认为由于无法检查形状中是否存在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

`

抱歉违反约定,但我得到类似的错误:

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

在我的场景中,我只是在存储Shape对象的类中将形状作为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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM