我是VBA环境的新手,我正在尝试从表“表1”中复制特定列的“Column1_name”,“Column_name”。 当我执行以下代码时,我收到的错误是“数据源名称太长”。 另外我不确定下面输入的Sql代码是否正确显示从oracle到excel的列。
需要手调试此错误和查询。 提前致谢
代码 -
Sub data_audit()
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim rs As New ADODB.Connection
Dim strConn As String
Dim sqlStr As String
strConn = "Driver={Oracle in OraClient11g_home1}; Dbq=; Uid=; Pwd=;"
cn.Open strConn
sqlStr = "SELECT distinct" & Chr(10)
sqlStr = sqlStr & "SAM_ID," & Chr(10)
sqlStr = sqlStr & "DP_QV_Name," & Chr(10)
sqlStr = sqlStr & "From CMS.CMS_SAM_ALL_DATA"
rs.Open sqlStr, strConn <<<<<< error" Missing Expression"
Sheets("Working").Range("J2:g1047856").ClearContents
Sheets("Working").Cells(2, 1).CopyFromRecordset rs
rs.Close
cn.Close
Set cn = Nothing
MsgBox " LOADED!"
End Sub