这里的代码是下面的代码,它在2015年5月5日/ 30日正常运行。但由于某种原因,它崩溃并给我下标范围错误。
我可能已经改变了一些链接,只是试图在概念上理解错误是什么,然后调试它。代码是OLEDB连接并按月提取数据
你能看看吗我没有得到导致错误的行,但是它发生的SOI调用。我在考虑它的连接问题所以会尝试删除OLEDB连接并重做它
Sub Update()
'PCAP
Call ReplaceConnectionandRefresh1("PCAP", "zzFS - PCAP- SCRF3", "Apollo", "DB_PEFS521", "TSCRLWSQLCLP162\PEFS02")
'Capital Activity Rec
Call ReplaceConnectionandRefresh1("INVESTRAN DATA", "zzCapital Activity by Position rec - SCRF3", "Apollo", "DB_PEFS521", "TSCRLWSQLCLP162\PEFS02")
'SOI
Call ReplaceConnectionandRefresh1("SOI from JPM investran", "zz_Schedule of Investments", "Apollo", "DB_PEFS521", "TSCRLWSQLCLP162\PEFS02")
'TB
Call ReplaceConnectionandRefresh1("Sheet2", "TB Summary_BS", "Apollo", "DB_PEFS521", "TSCRLWSQLCLP162\PEFS02")
MsgBox ("All Investran data tabs have been refreshed.")
End Sub
Sub ReplaceConnectionandRefresh1(spreadsheet As Variant, DriverName As String, RWFolder As String, dbName As String, ServerName As String)
'Sheets(spreadsheet).Visible = True
'Sheets(spreadsheet).Select
'Sheets(spreadsheet).Range("A1").Select
Set lstObj = Sheets(spreadsheet).ListObjects(1)
Set queryTbl = lstObj.QueryTable
queryTbl.Connection = "OLEDB;Provider=ftiRSOLEDB.RSOLEDBProvider;" _
& "Integrated Security=" & """" & """" _
& ";Location=" & dbName & ";User ID=" & """" & """" _
& ";Initial Catalog=" & dbName & ";Data Source=" & ServerName _
& ";Mode=Read;Persist Security Info=True;Extended Properties="
mycurrentvalue = """" & dbName & """"
mycurrentvalue = mycurrentvalue & "." & """" & RWFolder & """"
mycurrentvalue = mycurrentvalue & "." & """" & DriverName & """"
mycurrentvalue = mycurrentvalue & " " & """"
mycurrentvalue = mycurrentvalue & "begin date=" & Format(Range("BeginDate"), "mm/dd/yyyy") & """"
mycurrentvalue = mycurrentvalue & " " & """"
mycurrentvalue = mycurrentvalue & "End Date=" & Format(Range("EndDate"), "mm/dd/yyyy") & """"
mycurrentvalue = mycurrentvalue & " " & """"
mycurrentvalue = mycurrentvalue & "GL Begin Date=" & Format(Range("BeginDate"), "mm/dd/yyyy") & """"
mycurrentvalue = mycurrentvalue & " " & """"
mycurrentvalue = mycurrentvalue & "GL End Date=" & Format(Range("EndDate"), "mm/dd/yyyy") & """"
mycurrentvalue = mycurrentvalue & " " & """"
mycurrentvalue = mycurrentvalue & "Legal Entity=" & Range("LEID") & """"
mycurrentvalue = mycurrentvalue & " " & """"
mycurrentvalue = mycurrentvalue & "GL Date=" & Format(Range("EndDate"), "mm/dd/yyyy") & """"
mycurrentvalue = mycurrentvalue & " FLAGS[/SILENT]"
Debug.Print mycurrentvalue
queryTbl.CommandText = mycurrentvalue
queryTbl.Refresh BackgroundQuery:=False
End Sub
答案 0 :(得分:0)