我是Excel VBA的初学者。我想从Teradata数据库查询数据,并将输出结果输入到Excel表格的行中。当我写了下面的代码:通过Excel查询数据库VBA
Private Sub CommandButton1_Click()
Dim conn As Connection
Dim rec1 As Recordset
Dim thisSql As String
Set conn = New Connection
conn.Open "Driver=Teradata; DBCName=" & DBCName & ";UID=" & UID & ";PWD=" & PWD
thisSql = "simple select qyery here"
With .QueryTables.Add(Connection:=conn, Destination:=.Range("A1"))
.Sql = thisSql
.Name = "data"
.FieldNames = True
.Refresh BackgroundQuery:=False
End With
End Sub
我收到错误说“编译器错误:用户定义类型没有定义”
如何克服这个问题?我是否需要在代码中包含任何内容?
请帮
我使用MSVisualBasic 6.5编辑
它会告诉您哪一行? – lins314159
在线显示错误:昏暗conn作为连接 – SrinivasR