View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Scott Spence Scott Spence is offline
external usenet poster
 
Posts: 16
Default select worksheet and run macro

On each worksheet you will need to add an event handler for the sheet activate event, then pass the sheet name into the code you have written

So on each worksheet module add this:

Private Sub Worksheet_Activate()
Call ImportAlarms(Me.Name)
End Sub

Then I have amended your code to incorporate the sheet name parameter:

Sub ImportAlarms(strSheetName As String)
Dim thisSheet As Worksheet
Dim targetSheet As Worksheet

On Error GoTo failed

Set thisSheet = Application.ActiveSheet
Set targetSheet = Sheets(strSheetName)

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