使用VBA宏

时间:2017-12-06 11:41:27

标签: vba

我是VBA的新手,只想创建一个宏,在每个句点使用一个简单的vba宏将工作表(或工作表)从一个文件复制到另一个文件。

我确信这很简单但正如我所说,我是这个世界的新手!

非常感谢提前!

1 个答案:

答案 0 :(得分:1)

试试这个:(你很幸运,我有一个模板:)欢呼声

以下是代码:

Dim wkb1 As Workbook
Dim sht1 As Worksheet
Dim wkb2 As Workbook
Dim sht2 As Worksheet

Application.ScreenUpdating = False

Set wkb1 = ThisWorkbook
Set wkb2 = Workbooks.Open("B.xlsx")
Set sht1 = wkb1.Sheets("Roll Out Summary")
Set sht2 = wkb2.Sheets("Roll Out Summary")

sht1.Cells.Copy
sht2.Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
wkb2.Close True

Application.ScreenUpdating = True

仅限范围:

Set sht1 = wkb1.Sheets("Roll Out Summary").Range("A1:B10") ' Define the range
Set sht2 = wkb2.Sheets("Roll Out Summary")

sht1.Cells.Copy
sht2.Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
wkb2.Close True