VB Excel:如何使用表单/宏移动工作表

发布于 2024-08-06 16:27:45 字数 214 浏览 10 评论 0原文

我在将工作表转移到另一个工作簿时遇到问题。我在我的第一个工作簿中编写了几个宏,以及 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑脸一如从前 2024-08-13 16:27:45

要复制宏和表单,您需要从原始工作簿中导出它们,然后将它们导入到新工作簿中。

要导出,请右键单击原始工作簿中项目资源管理器中的相关表单或模块,然后选择导出文件。这将为表单创建一个 .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 use Import 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 called ThisWorkbook) 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

暮凉 2024-08-13 16:27:45

唯一的方法是“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...

半暖夏伤 2024-08-13 16:27:45

我可能会费尽心思,但通常当我需要将代码从一个工作簿移动到另一个工作簿(不是布局、命名范围等)时,我:

  • 打开两个工作簿
  • 打开 vba 编辑器 (alt + F11)
  • 从一个项目中拖动所需的模块进入另一个。

为了摆脱对其他工作簿的引用,我会尝试(不肯定它会起作用..)执行查找/替换,查找整个工作簿名称并将其替换为空字符串(“”)并确保在选项下你看看:公式(我相信)。

希望有帮助。

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:

  • Open both workbooks
  • Open the vba editor (alt + F11)
  • Drag desired modules from one project into another.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文