1

I have written some code for an excel spreadsheet. This sub has been added to the ribbon using the standard customizations found in File -> Options -> Customize Ribbon. What is funny though, is that the customization will run the Sub on the EXACT EXCEL FILE that the Sub is written in, i.e. the original.

My users copy the excel file and make adjustments and then run the sub (by clicking the customized button in the ribbon), which then opens the ORIGINAL template file and runs the code. This actually works fine - and I like it because it runs the TEMPLATE code on the ACTIVE sheet. But the only problem is it is also OPENING the original template file. How do I get it to close? Remember it is not the ActiveSheet anymore.

One possible answer is to check if the template is open, then close it (using a static reference), but I would prefer something a little more elegant than that.

4

1 回答 1

0

您应该能够使用ThisWorkbook.


此外,如果您将工作簿的代码作为 .xlam 而不是 .xlsm 提供,它将被打开,但不会有窗口,因此用户不会看到它。


不确定您是否已经在使用它,但在为 .xlam 添加功能区按钮时,您可能还想使用“仅用于此工作簿”。(以 .xlam 格式交付允许您将工作簿中的按钮安装到功能区中,而无需依赖文件路径,也不需要您的用户也安装按钮(他们安装的是 .xlam)。)

于 2013-01-06T16:12:58.590 回答