Share via

EXCEL: Error 50290 "Application-defined or object-defined error"

Ted David 0 Reputation points
2026-02-27T01:51:15.2133333+00:00

I have written some custom VBA for an application I use to teach dyslexic children. In an earlier version, I simply used a cell to post an instruction and the app worked. In an update, I am using the TextToSpeech capability and I get the error stated above. But note that TextToSpeech isn't used in this specific subroutine. However, the TextToSpeech capability works in other subroutines. The error occurs in a Worksheet_BeforeDoubleClick subroutine. I have used the Immediate window to check that the ActiveSheet variable is correct, and that the specific Range("Response") value and address are correct.

Here is the code. It is in the ActiveSheet's module.

It fails on the first instance of the line "ws.Range("Response").Value = ""

Please help:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Set ws = ActiveSheet **Note: dim ws as worksheet** **is in the module's Declarations**

Static Target2 As Range

ws.Range("Response").Value = "" **<-- Fails here, but the named range was checked and is OK**

Cancel = False ' Prevents entering Edit mode

If ActionUnderway = "Clicking Color" Then

    If Target.Cells.CountLarge = 1 Then

       SelectedColor = Target.Interior.Color

    End If

    ActionUnderway = "Change Color"

    ws.Range("Response").Value = "Now Double Click the Block you want to Change"

    Application.Speech.Speak "Now Double Click the Block you want to Change"

ElseIf ActionUnderway = "Delete Block" Then

    Target.Interior.Color = vbWhite

    Target.ClearFormats

    ActionUnderway = ""

ElseIf ActionUnderway = "Add Block" Then

    Set Target2 = Target

    ws.Range("Response").Value = "Now Double Click the Color for the Added Block"

    Application.Speech.Speak "Now Double Click the Color for the Added Block"

    ActionUnderway = "Color Added Block"

ElseIf ActionUnderway = "Change Color" Then

    If Target.Cells.CountLarge = 1 Then

       Target.Interior.Color = SelectedColor

    End If

    ActionUnderway = ""

ElseIf ActionUnderway = "Color Added Block" Then

     ws.Range("Response").Value = ""

    If Target.Cells.CountLarge = 1 Then

       SelectedColor = Target.Interior.Color

    End If

    Target2.Interior.Color = SelectedColor

    Target2.BorderAround LineStyle:=xlContinuous

    ActionUnderway = ""

Else

    Exit Sub

End If

End Sub

Microsoft 365 and Office | Excel | For education | Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sophie N 12,420 Reputation points Microsoft External Staff Moderator
    2026-02-27T02:50:56.3566667+00:00

    Dear @Ted David,

    Thank you so much for reaching out to the Microsoft Q&A forum.

    I completely understand how tricky it can be when a previously stable VBA project begins throwing Error 50290, especially when you are working on such a meaningful application for teaching children. I really appreciate you sharing your code and the specific steps you've already taken to verify your variables; it's clear you've put a lot of thought into diagnosing this.

    To protect the specifics of your project and ensure we can look at your code structure more closely, I’ve sent you a private message with a tailored technical explanation and some specific code-level suggestions to resolve this "Application-defined" error.

    User's image

    Please take a look at your private message inbox at your convenience. I’ve included some details there that should help bypass the conflict between the Speech engine and the Worksheet events.

    0 comments No comments

  2. Q&A Assist
    2026-02-27T01:51:30.7766667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Error 50290 “Application-defined or object-defined error” in this context indicates that the macro is calling a method or property in a way Excel cannot execute at that moment.

    From the provided code and the context, the most likely causes are:

    1. The named range Response is not valid in the sheet where the event fires
      • ws.Range("Response") requires that the name Response be defined with scope to that worksheet or as a workbook-level name that refers to a valid range on that sheet.
      • If Response is defined on a different sheet, or as a workbook name pointing elsewhere, ws.Range("Response") can raise an application/object-defined error.
      • Confirm in Formulas → Name Manager that:
        • There is a name Response.
        • Its Refers to points to a cell on the same sheet as this Worksheet_BeforeDoubleClick code.
    2. The macro is trying to access an object that does not exist or is not valid at the time of the event
      • This is a standard cause of macro errors in Excel: “trying to gain access to an object that does not exist; for example, Workbooks(5) when only three workbooks are open.” The same applies to named ranges that do not resolve correctly on the active sheet.
      • If the sheet is protected and the Response cell is locked, writing to it can also trigger an application-defined error.
    3. Unqualified or conflicting object references
      • Ensure ws is declared at module level as Dim ws As Worksheet and that no other variable or property named Response or ws exists in the same scope.
      • In event code, Me is safer than ActiveSheet. Replace:
             Set ws = ActiveSheet
        
        with:
             Dim ws As Worksheet
             Set ws = Me
        
        Then test again.
    4. General macro error conditions
      • The “Macro Error” guidance notes that this error appears when:
        1. An argument contains a value that is not valid.
        2. The method cannot be used in the applied context.
        3. An external error occurred.
      • In this case, the invalid argument/context is almost certainly the Range("Response") reference on ws.

    Practical fixes to try in order:

    1. Replace ActiveSheet with Me in the event procedure:
         Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
             Dim ws As Worksheet
             Set ws = Me
             ws.Range("Response").Value = ""
             ' ... rest of code
         End Sub
      
    2. Fully qualify the named range to the workbook, then to the sheet:
         ThisWorkbook.Names("Response").RefersToRange.Value = ""
      
      This bypasses ambiguity with ActiveSheet and ensures the name resolves.
    3. Verify and, if needed, recreate the Response name:
      • Delete the Response name in Formulas → Name Manager.
      • Select the intended cell on this worksheet and create a new name Response scoped to this sheet.
    4. If the sheet is protected, unprotect it or unlock the Response cell and allow edits in protected sheets.

    If, after these changes, the error persists, temporarily replace the failing line with a direct cell reference (for example, Me.Range("A1").Value = "") to confirm that the problem is specifically with the Response name resolution rather than the event or sheet itself.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.