VBA Windows(索引).Activate导致运行时错误“9”:下标超出范围

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

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 

尝试

 Workbooks(temp_name).Activate 

这将引用特定的Excel工作簿实例,因为我相信它无法find您打算引用的工作簿。 假设表单(“数据”)是一个工作表内的任何工作簿名称是在当时“temp_name”保存?

谢谢,

杰米