-1

我开始为 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

请帮忙
谢谢!

4

1 回答 1

0

我已将此 LastVariable_Check 称为此工作簿 wkbOut 的范围之外。只需在我将 wkbOut 保存为不同工作表名称的代码之前剪切粘贴并调用它,它就可以工作。

于 2012-09-14T10:59:49.010 回答