作者style90639 (school)
看板Visual_Basic
标题[VBA ] 阵列索引超出范围
时间Fri Jul 25 01:02:32 2014
我打算从EXCEL捞SQL的资料
但每次都会出现如题的讯息
是否能够帮我看看到底哪里的问题,
或者是否有验证错误的方法@@
Sub logsheet()
Dim ad, start_time, End_Time, eq_period, critera1, critera2 As String
Application.ScreenUpdating = False
ad = InputBox("请输入lotid")
ad = ucase(ad)
start_time = InputBox("请输入start_time,例如:yyyy/mm/dd", , Date - 3)
end_time = InputBox("请输入end_time,例如:yyyy/mm/dd", , Date + 1)
start_time = Format(start_time, "yyyy-mm-dd hh:mm:ss")
end_time = Format(end_time, "yyyy-mm-dd hh:mm:ss")
c1 = " WHERE AA1='" + ad + "' AND AA2='GG' AND AA4='W' AND AA3='T' AND
TIME >{ts '" + start_time + "'} AND TIME < {ts '" + end_time + "'}"
With Sheets("logsheet").Range("B1").QueryTable
.connection = "ODBC;DSN=****;UID=****;PWD=****;SERVER=****;"
.CommandText = "SELECT s.ad,s.st FROM AB1 " + c1
.Refresh BackgroundQuery:=False
End With
End Sub
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.169.170.222
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Visual_Basic/M.1406221354.A.6AB.html
1F:推 johnpage:请用excel 2010试 07/25 05:57
2F:推 aspx:可以先把SQL字串凑出来拿到SQL开发环境跑正不正常吗? 07/28 12:00
3F:→ aspx:顺便看看有几列,善意提醒VBA的连接符号是& 07/28 12:01