Hi,

I am trying to run some code when a worksheet is selected.

I'm doing this using a macro currently (code below), but this requires that i use a quick menu button and i would like to make it a form button and assign a macro to it (so i can distribute the file without everyone having to create a menu button).

I would like to replace (or modify) the code below to select any sheet other than the ones named "a" and "b".

Can someone help modify this code please ?

Many thanks,

Sub ImportAlarms()
    Dim thisSheet As Worksheet
    Dim targetSheet As Worksheet
 
    On Error GoTo failed
 
    Set thisSheet = Application.ActiveSheet
    Set targetSheet = Sheets(TARGET_SHEET)
 
    If (Not (thisSheet Is Nothing) And Not (targetSheet Is Nothing) And thisSheet.Name <> targetSheet.Name) Then
 
        If (thisSheet.Cells(1, 1) = "Profile Alarms") Then
 
            Call importSheet(thisSheet)
 
        Else
            Call MsgBox("Please select an Alarm sheet")
        End If
    Else
        Call MsgBox("Please select an Alarm sheet")
    End If
 
    Exit Sub
 
failed:
    Call MsgBox("Please select an Alarm sheet")
 
End Sub