VBA 窗口(索引)。激活原因运行时错误"9":下标超出范围



我有一个几乎完整的VBA宏,运行良好,直到它达到这一行:

Windows(temp_name).Activate

当我运行这个时,我得到以下错误:

运行错误'9':

下标超出范围

temp_name是我需要返回的文件的名称。这里有一些行(如果需要更多行请告诉我):

Next Ind
Application.CutCopyMode = False
Workbooks.OpenText Filename:=CPath _
    , Origin:=437, startRow:=1, DataType:=xlDelimited, TextQualifier:= _
    xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
    , Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
    Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
    Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1)), _
    TrailingMinusNumbers:=True
For Ind1 = 1 To iPlateNo
TLCorn = "B" + CStr(iStartrow + (Ind1 - 1) * iStep)
BRCorn = "M" + CStr(iStartrow + 7 + (Ind1 - 1) * iStep)
RangeNOut = TLCorn + ":" + BRCorn
RangeNIn = TLCorn
Windows(FileN).Activate
Range(RangeNOut).Select
Selection.Copy
Windows(temp_name).Activate
Sheets("Data").Select
Range(RangeNIn).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Next Ind1
'   Calculation of background and efflux for individual plates
For Ind1 = 1 To iPlateNo / 2
    iStep2 = (Ind1 - 1) * iStep * 2
    iBgrRow = iStartrow + 8 + iStep2
    BgrValP = Cells(iBgrRow, 2).Value
    For Ind2 = 0 To 7
        iEntryRow = iStartrow + Ind2 + iStep2
        iEntryRow2 = iStartrow + Ind2 + iStep2 + 11
        MediaVal = Cells(iEntryRow, 13).Value
        MonoVal = Cells(iEntryRow2, 13).Value
        Cells(iEntryRow, 15).Value = MEeff * 100 * Volcorr * (MediaVal - BgrValP) / (M40eff * MonoVal + Volcorr * MEeff * (MediaVal - BgrValP))
    Next Ind2
Next Ind1

Try

Workbooks(temp_name).Activate 

这将引用特定的Excel工作簿实例,因为我认为它无法找到您打算引用的工作簿。假设工作表("数据")是在"temp_name"中持有的任何工作簿名称中的工作表?

谢谢,杰米

最新更新