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