尝试复制工作表时出错

时间:2017-07-13 19:43:07

标签: excel vba excel-vba

我遇到错误" Worksheeet类的复制方法失败"在这一行:

.Sheets("Blank Forecast Sheet").Copy After:=.Sheets("Button Sheet")

我环顾四周,无法找到任何解决方案。可以看出,这段代码应该添加我将重命名的新工作表,一旦我解决了这个问题。

Sub addnewsheet()

Dim wbook As Workbook
Set wbook = Application.ActiveWorkbook

Dim newsheet As Worksheet
Dim datasheet As Worksheet

Dim m As String
Dim y As Integer

m = Format(Date, "mmmm")
y = Format(Date, "yyyy")

With wbook
.Sheets("Blank Forecast Sheet").Copy After:=.Sheets("Button Sheet")
End With

End Sub

1 个答案:

答案 0 :(得分:0)

使用ThisWorkbook代替wbook.Worksheets代替.Sheets

Sub addnewsheet()

Dim newsheet As Worksheet
Dim datasheet As Worksheet

Dim m As String
Dim y As Integer

m = Format(Date, "mmmm")
y = Format(Date, "yyyy")

With ThisWorkbook
    .Worksheets("Blank Forecast Sheet").Copy After:=.Worksheets("Button Sheet")
End With

End Sub