我有一个几乎完整的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
答案 0 :(得分:0)
尝试
Workbooks(temp_name).Activate
这将引用特定的Excel工作簿实例,因为我认为它无法找到您要引用的工作簿。假设表格("数据")是一个工作表,无论工作簿名称保存在" temp_name"当时?
谢谢,
杰米