C# Excel dropdown event

心不动则不痛 提交于 2019-12-06 03:56:43

I just did a small example based on your code. After some googling around and testing some source code pieces it comes down to a single line of code:

xlDropDown.Name = "expFail" + (x + 1).ToString(); // your code
xlDropDown.OnAction = xlDropDown.Name + "_Change"; // new code: IMPORTANT

Found this code within an Microsoft KB article How To Create an Excel Macro by Using Automation from Visual C# .NET.

It seems that you need this line of code to set some kind of delegate pointing to your custom vba code.

In case you need my complete source let me know and I will mail it to you.

You have to write the change event to the Worksheet where you create the combobox (not to the VBA module "module2". The combobox is part of the Worksheet(object) and all the event handlers have to be there.

Based on this article you need to write the code to the Worksheet_Change event, not the ComboBox_Change event:

Sub Worksheet_Change(ByVal Target As Range)
    Call lstBoxUpdate("expFail1")
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!