|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我试过,没问题
- Sub EXCEL内读SQL()
- Dim sSQL_Server As String
- Dim sDataBaseName As String
- Dim sDBFormName As String
-
- Dim oRead_SQL_Conn As Object
- Dim sSQL_Select As String
-
- sSQL_Server = "192.168.1.231"
- sDataBaseName = "abc"
- sDBFormName = "Style"
-
- Set oRead_SQL_Conn = CreateObject("Adodb.Connection")
- oRead_SQL_Conn.Open "Provider=SQLOLEDB; User ID=sa;Password =”“”“;Database=" & sDataBaseName & ";Data Source=" & sSQL_Server
- sSQL_Select = "select DISTINCT 代码,描述,尺寸,单位 from style"
- [A2].CopyFromRecordset oRead_SQL_Conn.Execute(sSQL_Select)
- sSQL_Select = "select 代码,描述,尺寸,单位 from style group by 代码,描述,尺寸,单位"
- [G2].CopyFromRecordset oRead_SQL_Conn.Execute(sSQL_Select)
-
- oRead_SQL_Conn.Close
- Set oRead_SQL_Conn = Nothing
- End Sub
复制代码 |
|