如何使用vba将工作表复制到另一个工作簿? [英] How to copy sheets to another workbook using vba?

查看:6515
本文介绍了如何使用vba将工作表复制到另一个工作簿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想做的一般是制作一本工作簿的副本。但是,源代码工作簿正在运行我的宏,我希望它能够自己创建一个相同的副本,但没有宏。我觉得应该有一个简单的方法来做到这一点与VBA,但还没有找到它。我正在考虑将纸张逐一复制到我将要创建的新工作簿中。我该怎么做?有更好的方法吗?

So, what I want to do, generally, is make a copy of a workbook. However, the source workbook is running my macros, and I want it to make an identical copy of itself, but without the macros. I feel like there should be a simple way to do this with VBA, but have yet to find it. I am considering copying the sheets one by one to the new workbook, which I will create. How would I do this? Is there a better way?

推荐答案

有人在 Ozgrid 回答了一个类似的问题。基本上,您只需将Workbook1中的每张表复制到Workbook2。

Someone over at Ozgrid answered a similar question. Basically, you just copy each sheet one at a time from Workbook1 to Workbook2.

Sub CopyWorkbook()

    Dim currentSheet as Worksheet
    Dim sheetIndex as Integer
    sheetIndex = 1

    For Each currentSheet in Worksheets

        Windows("SOURCE WORKBOOK").Activate 
        currentSheet.Select
        currentSheet.Copy Before:=Workbooks("TARGET WORKBOOK").Sheets(sheetIndex) 

        sheetIndex = sheetIndex + 1

    Next currentSheet

End Sub

免责声明:我还没有尝试过代码只是采用链接的例子来解决你的问题。如果没有别的话,它应该引导你朝着你想要的解决方案。

Disclaimer: I haven't tried this code out and instead just adopted the linked example to your problem. If nothing else, it should lead you towards your intended solution.

这篇关于如何使用vba将工作表复制到另一个工作簿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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