我编写了这段代码,用于将工作表从一个工作簿移动到另一个工作簿。它一直工作到昨天,突然投掷
Run time error '1004': Workbook is protected and cannot be changed
以下是代码。 Debug显示END SUB
之前的最后一个语句是问题。我无法弄清楚什么是错的。
Sub copydata()
Dim wkbSource As Workbook
Dim wkbDest As Workbook
Dim shttocopy As Worksheet
Dim wbname As String
' check if the file is open (source file)
ret = Isworkbookopen("C:\Users\Desktop\Scorecard\Write Offs.xlsx")
If ret = False Then
' open file
Set wkbSource = Workbooks.Open("C:\Users\Desktop\Scorecard\Write Offs.xlsx")
Else
Set wkbSource = Workbooks("Write Offs.xlsx")
End If
' check if the file is open
ret = Isworkbookopen("C:\Users\Desktop\Scorecard\Copy data from one excel to another.xlsm")
If ret = False Then
' open file
Set wkbDest = Workbooks.Open("C:\Users\Desktop\Scorecard\Copy data from one excel to another.xlsm")
Else
Set wkbDest = Workbooks("Copy data from one excel to another.xlsm")
End If
'Sheet to be copied from the PEH write off report
Set shttocopy = wkbSource.Sheets("PEH WBB TOTAL MPG")
shttocopy.Copy wkbDest.Sheets(1)
End Sub