Excel Vba:在创建新工作表时执行事件或宏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5128124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel Vba : Execute event or macro on creation of new sheet
提问by Balaji.N.S
I am trying to create a drop downon a particular column on creation of a new sheetby the user.
我正在尝试在用户创建新工作表时在特定列上创建下拉列表。
The drop down is present as a template in a hidden sheet which needs to be populated on creation of a new sheet on a particular column.
下拉列表作为隐藏工作表中的模板存在,需要在特定列上创建新工作表时填充该模板。
1) I guess there should be some event which needs to be triggered on creation of new sheetand den call a macro
1)我想应该有一些事件需要在创建新工作表和 den 调用宏时触发
2) The macro will populate each cell in a particular column with the list of values
2) 宏将使用值列表填充特定列中的每个单元格
Can some one guide me how to do this....
有人可以指导我如何做到这一点......
回答by chris neilsen
In VBA, in the ThisWorkbook module, you can create an event handler for the New Sheet event:
在 VBA 中,在 ThisWorkbook 模块中,您可以为 New Sheet 事件创建一个事件处理程序:
Private Sub Workbook_NewSheet(ByVal Sh As Object)
<copy stuff from ThisWorkbook.Worksheets("TemplateSheetName") to sh.cells(...)>
End Sub