cConnect = "ODBC;DRIVER={Microsoft ODBC for Oracle};UID=root;SERVER=testdb;PWD=root"
For i = 1 To iEndrow
Lotid = Sheets("lotlist").Range(Cells(iEndrow, "A"), Cells(iEndrow, "A")).Value
sqlstr = "insert into mfg_tb_autopri_wait_terList values('" + Lotid + "','" + iuser + "','" + itime + "')"
With ActiveSheet.QueryTables.Add(Connection:=cConnect, Destination:=Range("A1"))
.CommandText = sqlstr
.Name = "查询来自 FP8DB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Next
这段报错,原本这段是查询用的。查询用以下这段是没问题的
With ActiveSheet.QueryTables.Add(Connection:=cConnect, Destination:=Range("A1"))
.CommandText = sqlstr
.Name = "查询来自 FP8DB"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With