EXCEL 2007 - 需要帮助创建一个按钮,该按钮获取活动工作表的内容并将其粘贴到新工作表中
我在整个网站上进行了搜索,以找到我的问题的答案,大多数相关的解决方案都是针对更复杂的问题。这是我需要做的。我在 Excel 2007 中创建了一个简单的表单。我正在寻找在表单底部添加一个按钮的功能,该按钮允许用户单击该按钮并将该工作表复制到同一 Excel 文档中的新工作表中。基本上只是复制活动工作表。
我尝试使用宏来做到这一点,但没有得到预期的结果,而且我们的大多数同事仍然使用 Excel 2003,所以我不确定宏是否可以在旧版本的 Excel 中工作。我不懂任何VBA,这就是为什么我来这里寻求大家的帮助。
所以回顾一下。
- 一张 Excel 文档,其中有一个简单的表单,活动工作表底部有一个命令按钮 命令
- 按钮“复制并粘贴”该工作表到同一 Excel 文档中的新工作表 一个
- 可以在 Excel 2003 和 2007 中工作的解决方案,如果可能的。如果没有,就 2007 年吧。
提前非常感谢任何愿意帮助 Excel 新手的人。
I have search throughout this site to find a answer to my problem and most of the related solutions are for a far more complicated problem. Here is what I need to have done. I created a simple form in Excel 2007. I am looking for the ability to add a button at the bottom of the form which allows the user to click on the button and copy that worksheet into a new worksheet within the same excel document. Basically just duplicating the active worksheet.
I tried to do it with macros but did not get the desired results, and most of our co-workers still use Excel 2003 so I am not sure if macros will work in the older version of excel. I do not know any VBA which is why I come here in search of help from you all.
So to recap.
- One sheet Excel document with a simple form and a command button at the bottom of the active worksheet
- The command button "Copy and Paste" that worksheet into a new worksheet within the same excel document
- A solution that could work in both Excel 2003 and 2007 if possible. If not, for 2007.
Thanks so much ahead of time for anyone who is willing to help out a Novice Excel User.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设您知道如何添加按钮,这里有一行简单的代码来复制活动工作表:
Assuming that you know how to add a button here is a simple line of code to duplicate the active worksheet:
也许是这样的(仅在 Excel 2003 中测试):
Maybe something like this (tested in Excel 2003 only):
您应该发现此方法适用于 Excel 2003 和 Excel 2007。在您的表单中,添加以下方法:
从按钮单击事件中,使用以下方式调用它:
这将在当前工作表和下一个工作表之间转储工作表的副本一。我已经在 Excel 2003 和 Excel 2007 中对其进行了测试,并且它在两者中都有效。遗憾的是,它没有给第二个工作表一个漂亮的名字 - 它只是与源工作表同名,并在其后面加上 (2) 。
所有格式、保护和公式也被复制 - 这是第一个的副本。
You should find this method will work in both Excel 2003 and Excel 2007. In your form, add the following method:
From the button click event, call it using:
This will dump a copy of the worksheet in between the current sheet and the next one. I've tested it in Excel 2003 and Excel 2007 and it works in both. It doesn't give the second one a pretty name sadly - it just gets the same name as the source worksheet with (2) put after it.
All the formatting, protection and formulas are copied across too - it's a carbon copy of the first.
我知道这个问题已经很老了,但只是想指出,您(和用户)可以使用零代码执行完全相同的操作:右键单击底部的工作表名称,然后选择“移动”或“复制”.. .,然后选中创建副本框并单击确定。是的,只需点击 4 次,但它非常简单并且无需编写代码。
I know the question is quite old, but just wanted to note that you (and the user) can do the exact same thing with zero code: right-click on the sheet name at the bottom and select Move or Copy..., then check the Create a copy box and click Ok. Yes, it takes 4 clicks, but it is super easy and avoids code.