将工作表从一个工作簿复制到另一个工作簿。类型不匹配13

时间:2014-04-13 19:12:24

标签: excel vba excel-vba

我希望将一个工作表从工作簿复制到另一个工作表,然后更改名称。没什么大不了的。

我一直遇到类型不匹配错误,我不知道为什么。我使用过他们认为合适的代码而不是我的代码。

任何想法。

Private Sub cmdStockLog_Click()

week = ThisWorkbook.Sheets("Stock Sheet").Range("F1")

Dim wb As Workbook
Set wb = Workbooks.Open(ThisWorkbook.Path & "\Data\FOH Stock.xlsx")

ThisWorkbook.Sheets("Stock Sheet").Copy After:=Workbooks(wb).Sheets(Worksheets.Count)
ActiveSheet.Name = "WK" & week

End Sub

1 个答案:

答案 0 :(得分:1)

试试这段代码:

Private Sub cmdStockLog_Click()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim week

    week = ThisWorkbook.Sheets("Stock Sheet").Range("F1")

    Set wb = Workbooks.Open(ThisWorkbook.Path & "\Data\FOH Stock.xlsx")

    ThisWorkbook.Sheets("Stock Sheet").Copy After:=wb.Sheets(wb.Sheets.Count)
    Set ws = wb.Sheets(wb.Sheets.Count) ' new sheet
    ws.Name = "WK" & week
End Sub