我开始为excel 2007学习VBA。任何人都可以帮助执行此错误的原因:
代码是
Public Sub LastVariable_Check()
'Check if Last Variable is of latest month sales
'lastvariable = lv
lv = wkbOut.Sheets("Sheet1").Range("B1",Range("B1").End(xlToRight)).End(xlToRight).Text
If "0" & Mid(lv, InStr(lv, "Month/") + 6, 1) = strmth _
And Mid(lv, InStr(lv, "Month/") + 8, 4) = strYear Then
Set wkbRaw = Workbooks.Open(strInputQCPath & "Errorlog.xlsx")
wkbRaw.Sheets("Sheet1").Range("A1").Offset(i, 2).Value = "Correct"
wkbRaw.SaveAs Filename:=strInputQCPath & "Errorlog.xlsx"
wkbRaw.Close
Else
Set wkbRaw = Workbooks.Open(strInputQCPath & "Errorlog.xlsx")
wkbRaw.Sheets("Sheet1").Range("A1").Offset(i, 2).Value = "Incorrect"
wkbRaw.SaveAs Filename:=strInputQCPath & "Errorlog.xlsx"
wkbRaw.Close
End If
End Sub
请帮助
谢谢!
答案 0 :(得分:0)
我已经调用了这个LastVariable_Check,超出了本工作簿wkbOut的范围。只是剪切粘贴并在代码之前调用它,我将wkbOut保存为不同的工作表名称并且它有效。