跨工作簿共享VBA模块 [英] Sharing VBA Modules across Workbooks

查看:281
本文介绍了跨工作簿共享VBA模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多工作簿.每个工作簿都包含许多电子表格,除了所携带的数据外,所有工作簿都完全相同.每个工作簿都有许多VBA模块,当我对一个模块进行更改时,我需要将对所有其他模块的相同更改推送到所有其他工作簿.

I have a number of workbooks. Each workbook contains a number of spreadsheets, and all workbooks are exactly the same, except for the data they carry. Each workbook has a number of VBA modules, and when I make changes to one module, I then need to push the same changes to all other modules to all other workbooks.

是否可以在所有工作簿中共享VBA模块,所以我只能在一个地方进行更改?

Is there a way to share the VBA modules across all of my Workbooks, so I can make changes only in one place?

推荐答案

将代码移动到单独的Excel工作簿中,并将其另存为.xlam(启用Excel宏的加载项).

Move the code into a separate Excel workbook and save it as .xlam (Excel macro-enabled add-in).

从所有其他文件的工具-引用中引用加载项(单击浏览,将文件类型更改为"Microsoft Excel文件",然后导航到xlam文件).

Reference the add-in from all the other files' Tools - References (click Browse, change the file type to "Microsoft Excel files" and navigate to the xlam file).

仔细阅读代码,确保正确编写代码,并正确引用工作簿和工作表.例如. ThisWorkbook现在将引用加载项工作簿,而不是调用它的文档.

Go through the code and make sure it is written correctly and properly references workbooks and worksheets. E.g. ThisWorkbook will now refer to the add-in workbook, not to the document calling it.

这篇关于跨工作簿共享VBA模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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