簡體   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