动态将代码添加到新的Excel工作表 [英] Adding code to new excel sheet dynamically

查看:132
本文介绍了动态将代码添加到新的Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于VBA,我需要一些帮助. 在我的代码中,我添加了一个excel工作表,并将其重命名并添加了一个验证列表.我需要在更改该验证列表中的值时运行一些代码,并且该代码只能在更改该特定单元格时运行. 如果不清楚,请告诉我.请帮助我解决此问题.

解决方案

而不是尝试使用Visual Basic可扩展性为每个新工作表创建单独的代码(请参见 解决方案

Instead of trying to create the individual code for each new worksheet with the Visual Basic Extensibility (see this link for further reading), simply use the Workbook wide event Workbook_SheetChange (you need to place it in the ThisWorkbookmodule).

In this event code first check, if the worksheet which caused the event is one of the newly created worksheets. This can be done most easily, be checking the .Name of the worksheet.

这篇关于动态将代码添加到新的Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆