开发者

VBA: Worksheet.OnActivate

开发者 https://www.devze.com 2022-12-25 03:05 出处:网络
I have a method in my VBA code that needs to be assigned to a workbook. I tried: sht.Onactivate = \"Sheet_Activate\"

I have a method in my VBA code that needs to be assigned to a workbook.

I tried:

sht.Onactivate = "Sheet_Activate"

Howeve开发者_如何学编程r, this does not work. How can I assign this method to the worksheet.OnActivate event using VBA code?


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


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


In the VBA editor, in the Project Explorer Select the worksheet, right click and select View Code In the upper left drop down list choose Worksheet In the upper right drop down list choose Activate

You can also do this in the Workbook object gl hf

0

精彩评论

暂无评论...
验证码 换一张
取 消