tags:

views:

26

answers:

2

Hi,

I have a method in my VBA code that needs to be assigned to a workbook How can I assign this method to the worksheet.OnActivate event using VBA code?

I tried: sht.Onactivate = "Sheet_Activate"

But this doesn't work and I need something on these lines.

Thanks.

A: 

If the code needs to apply to the worksheet staticly (meaning, this code should always be hooked with the worksheet's activate event), you can simply add the following in the worksheet's VBA editor:

Private Sub Worksheet_Activate()
    MyCodeHere()
End Sub
M.A. Hanin
Thanks Hanin. However, I am trying to assign a method in my VBA code to the onclick of sheet. Hence, I cannot use the Worksheet_Activate() direcly.
Rashmi Pandit
A: 

I was able to assign a method to the event using the following code:

sheet.OnSheetActivate = "MyOwn_Activate"


Private Sub MyOwn_Activate()

    myForm.Show

End Sub
Rashmi Pandit