简体   繁体   English

Excel VBA - 在应用程序打开时运行宏

[英]Excel VBA - Run macro on Application open

I've got this Design Template I want to apply to the application by default whenever it's opened. 我有这个设计模板我想在应用程序打开时默认应用于该应用程序。 But a document needs to be open in order to apply a Design template. 但是需要打开文档才能应用设计模板。 So I have to target some handlers whenever a new or existing workbook is opened/created. 因此,无论何时打开/创建新的或现有的工作簿,我都必须针对一些处理程序。

So which approach can I take here? 那么我可以采取哪种方法?

I think you can use the Workbook_open event. 我想你可以使用Workbook_open事件。 It sounded like that would be sufficient for the behavior that you want, but since you want your macros to be global, you might need to make them into an add in for them. 对于你想要的行为来说,这听起来已经足够了,但是由于你希望你的宏是全局的,你可能需要将它们变成一个加入它们。

The add-in approach is best for applying to existing workbooks. 加载项方法最适合应用于现有工作簿。

If you're looking to have a standard design template applied to each new workbook, though, I suggest you create a template. 但是,如果您希望将标准设计模板应用于每个新工作簿,我建议您创建一个模板。

To do this: 去做这个:

  1. Create a new empty workbook 创建一个新的空工作簿
  2. Apply the design template 应用设计模板
  3. Save the file as Book.xlt (for Excel 2003; Book.xltx for versions 2007, 2010) in the following folder: %appdata%\\Microsoft\\Excel\\XLSTART\\ 在以下文件夹中将文件另存为Book.xlt(适用于Excel 2003;适用于版本2007,2010的Book.xltx): %appdata%\\Microsoft\\Excel\\XLSTART\\

Each time you create a new workbook (by opening Excel or hitting the "New" button), it'll be generated from this template file. 每次创建新工作簿(通过打开Excel或点击“新建”按钮),它都将从此模板文件生成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM