作者:乔山办公网日期:
返回目录:excel表格制作
sub test()
Dim Conn As New ADODB.Connection
Dim strConn As String
Dim strSQL As String
Dim rs As New ADODB.Recordset
strConn = "Provider=sqloledb;Server=192.168.1.111;Database=db2014;Uid=用户名复;Pwd=密码制;"
Conn.Open strConn
Max_row = Range("A1").CurrentRegion.Rows.Count
for i=1 to Max_row
strSQL = "select name from sales2014 where id='" & range("A" & i).value & "'"
Conn.Execute strSQL
rs.Open strSQL, Conn, 1, 1
range("B" & i).value= rs(0)
rs.Close
Set rs = Nothing
next i
'关闭数知据库道
Conn.Close
end sub
sub test()
Dim Conn As New ADODB.Connection
Dim strConn As String
Dim strSQL As String
Dim rs As New ADODB.Recordset
strConn = "Provider=sqloledb;Server=192.168.1.111;Database=db2014;Uid=用户zhidao名;Pwd=密码版;"
Conn.Open strConn
Max_row = Range("A1").CurrentRegion.Rows.Count
for i=1 to Max_row
strSQL = "select name from sales2014 where id='" & range("A" & i).value & "'"
Conn.Execute strSQL
rs.Open strSQL, Conn, 1, 1
range("B" & i).value= rs(0)
rs.Close
Set rs = Nothing
next i
'关闭数据库权
Conn.Close
end sub