VB Excel:如何使用表单/宏移动工作表
我在将工作表转移到另一个工作簿时遇到问题。我在我的第一个工作簿中编写了几个宏,以及 1 个或 2 个表单,并且我需要能够将包含这些宏和表单的工作表移动到新的工作簿中。如果我只是进行简单的工作表复制,则新版本的工作表将引用旧工作表的宏,并且当我尝试加载第二个工作表时,我编写的表单(在第一个工作表中)不会启动。
有什么建议吗?我尝试过谷歌搜索,似乎没有任何类似的问题......也许我错过了一些东西?
I'm having a problem transferring a worksheet into another workbook. I've written several macros in my first workbook, as well as 1 or 2 forms, and I need to be able to move this worksheet that contains these macros and forms into a new workbook. If I just do a simple worksheet copy, the new version of the worksheet will reference the old worksheet's macros, and the forms I wrote (in the first worksheet) don't launch when I try to load in the second worksheet.
Any suggestions? I've tried googling and there don't seem to be any similar problems... maybe I'm missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要复制宏和表单,您需要从原始工作簿中导出它们,然后将它们导入到新工作簿中。
要导出,请右键单击原始工作簿中项目资源管理器中的相关表单或模块,然后选择
导出文件
。这将为表单创建一个.frm
文件,或为模块创建一个.bas
文件。然后,您可以转到新工作簿并以相同的方式使用导入文件
。如果您使用了资源管理器的 Microsoft Excel 对象部分中的特殊模块(例如名为
Sheet1
的模块或名为ThisWorkbook
的模块),您可能会发现这些模块并不正确导入。对于这些,只需将宏的源代码从一个工作簿复制并粘贴到另一个工作簿To copy the macros and the forms, you need to export them from the original workbook and then import them to the new workbook.
To export, right-click on the relevant form or module in the Project Explorer in the original workbook and choose
Export File
. This will create a.frm
file for a form or a.bas
file for a module. You can then go to the new workbook and useImport File
in the same way.If you have used the special modules from the Microsoft Excel Objects section of the explorer (e.g. the module called
Sheet1
or the one calledThisWorkbook
) you will probably find that these do not import correctly. For those ones, just copy and paste the source code of the macros from one workbook to the other唯一的方法是“barrowc”建议的方法。但是,您可能想判断哪一个更容易,将宏工作表移动到新的工作表或将工作表从新文件移动到带有宏的工作表:)
干杯...
The only method is as suggested by 'barrowc'. However you may want to judge which one is more easier, moving the macro sheet to the new one or moving sheets from new file to the one with macro :)
Cheers...
我可能会费尽心思,但通常当我需要将代码从一个工作簿移动到另一个工作簿(不是布局、命名范围等)时,我:
为了摆脱对其他工作簿的引用,我会尝试(不肯定它会起作用..)执行查找/替换,查找整个工作簿名称并将其替换为空字符串(“”)并确保在选项下你看看:公式(我相信)。
希望有帮助。
I may be belaboring the obvious, but usually when I need to move code from one workbook to another (not the layouts, named ranges, etc) I:
To get rid of the references to the other workbook, I would try (not positive it would work..) doing a Find/Replace, Find the entire workbook name and replace it with an empty string ("") and make sure under options you Look in: Formulas ( I believe ).
Hope that helps.