|
楼主 |
发表于 2024-11-19 14:02
|
显示全部楼层
- Sub 测试()
- Set sh1 = ThisWorkbook.Worksheets(1)
- '----------------------------------------------------------------------------------------------------------
- Set cn = CreateObject("ADODB.Connection")
- Set rs = CreateObject("ADODB.Recordset")
-
-
- cn.ConnectionTimeout = 0
- cn.CommandTimeout = 0
-
- ID = "*******" '服务器IP
-
- Database = "*******" '数据库名称
-
- PassWordChr = "******" '密码
-
- cnStr = "Provider=sqloledb;Server=" & ID & ";Database=" & Database & ";Uid=****;Pwd=" & PassWordChr & ";"
-
- cn.Open cnStr '打开服务器对应的SQL数据库
-
- Sql = "Exec GetFPlanmx '','','','',0,1" '存储过程
-
- sh1.Cells(2, 1).Value = Sql '确认存储过程语句
-
- Set rs = cn.Execute(Sql) '赋值rs为存储过程数组
-
- sh1.Cells(6, 1).CopyFromRecordset rs '复制粘贴
- rs.Close
-
- Set rs = Nothing
-
- cn.Close
- Set cn = Nothing
- End Sub
复制代码 |
|