Excel VBA,需要帮助,RTE-9,不知道为什么

所以下面是代码。 我明白这不是最有效的,但即时学习的VBA,和优秀的代码>工作代码>破碎的代码。 现在即时在工作代码(或尝试)。

无论如何,代码,那么我的问题是什么

Sub PassToProc() Dim arr(4) As String arr(0) = "https://sharepoint/Time Sheets/Jeff.xlsm" arr(1) = "https://sharepoint/Time Sheets/Jonathan.xlsm" arr(2) = "https://sharepoint/Time Sheets/Jim.xlsm" arr(3) = "https://sharepoint/Time Sheets/Topher.xlsm" arr(4) = "https://sharepoint/Time Sheets/Brandon.xlsm" ' Pass the array to function UseArray arr End Sub Function UseArray(ByRef arrs() As String) Dim name As String Dim i As Integer For i = LBound(arrs) To UBound(arrs) If Cells(3, i + 4) <> "" Then name = Cells(3, i + 4) Select Case name Case "Jeff" Call InfoPuller(arrs, 0) Case "Jonathan" Call InfoPuller(arrs, 1) Case "Jim" Call InfoPuller(arrs, 2) Case "Topher" Call InfoPuller(arrs, 3) Case "Brandon" Call InfoPuller(arrs, 4) End Select End If Next i End Function Sub InfoPuller(ByRef link() As String, i As Integer) Dim Pay1 As String, Pay2 As String, PayPeriod As String Dim wkb As Workbook Pay1 = Format(Cells(3, 2), "m-dd") Pay2 = Format(Cells(24, 1), "m-dd") PayPeriod = "" & Pay1 & " -- " & Pay2 & "" 'Jeff (x,4) i = 0 'Jon (x,5) i = 1 'Jim (x,6) i = 2 'Topher (x,7) i = 3 'Brandon (x,8) i = 4 Set wkb = Workbooks.Open(link(i)) ' Pay period 1 Fill in For j = 5 To 11 ThisWorkbook.Sheets(PayPeriod).Cells(j, i + 4) = Workbooks.Open(link(i)).Worksheets(PayPeriod).Cells(j + 4, 9).Value Next j ' Mileage / Bridge Week 1 Dim Mileage As Integer, Bridge As Integer, Store As Integer, Store2 As Integer Dim MandB As String Mileage = Workbooks.Open(link(i)).Worksheets(PayPeriod).Cells(28, 3).Value Bridge = Workbooks.Open(link(i)).Worksheets(PayPeriod).Cells(29, 3).Value MandB = Mileage & " / " & Bridge ThisWorkbook.Sheets(PayPeriod).Cells(13, i + 4) = MandB Store = Mileage Store2 = Bridge 'Pay Period 2 Fill in For j = 18 To 24 ThisWorkbook.Sheets(PayPeriod).Cells(j, i + 4) = Workbooks.Open(link(i)).Worksheets(PayPeriod).Cells(j + 1, 9).Value Next j ' Mileage / Bridge Week 2 Mileage = Workbooks.Open(link(i)).Worksheets(PayPeriod).Cells(28, 4).Value Bridge = Workbooks.Open(link(i)).Worksheets(PayPeriod).Cells(29, 4).Value MandB = Mileage & " / " & Bridge ThisWorkbook.Sheets(PayPeriod).Cells(26, i + 4) = MandB Store = Store + Mileage Store2 = Store2 + Bridge MandB = Store & " / " & Store2 ThisWorkbook.Sheets(PayPeriod).Cells(31, i + 4) = MandB wkb.Close SaveChanges:=True End Sub 

所以这个(从数组名称)的基本思想是时间表。 我有一个主时间表,每个人都有它的名字,+日子。 概念是,按macrosbutton,它通过代码运行,从数组的L / UBounds打开http链接。 从特定工作表中抓取数据,将其放入我的工作表中,closures该工作簿,转到下一个名称。 即时通讯运行的问题是这一行。

  For j = 5 To 11 ThisWorkbook.Sheets(PayPeriod).Cells(j, i + 4) = Workbooks.Open(link(i)).Worksheets(PayPeriod).Cells(j + 4, 9).Value Next j 

ThisWorkbook引用macros的运行的MasterSheet。 PayPeriod由date决定。 Workbooks.Open(链接(我)…是因为如果我尝试工作簿(链接(我)),它不喜欢它(但它只打开1副本,所以我不担心重复)。

无论如何,上面的snippit,只要它执行Thisworkbook.sheets(PayPeriod),就是当我碰到RTE-9的问题。 单元格排队,我的拉数据是正确的,它只是打RTE-9下标超出范围。 任何想法的人? 是的,我缩短了https链接到只是共享点,它不是真正的链接,但隐私和所有