问题描述:
office2013升级为2016版本,Excel启用宏会报错
错误信息:
1.错误代码:3706,未找到提供程序,该程序可能未正确安装
调试后标黄语句:
Call getRsData.getConn("BASE")
2.错误代码:3709,连接无法用于执行此操作。在此上下文中它可能已被关闭或无效
调试后标黄语句:
Call getRsData.GetRs(strSql)
--
代码如下:
--getRsData 实例
Public getRsData As New pubDBCls
--
'获取数据库连接
Sub getConn(ByVal connType As String)
'判断日期信息是否正确
Dim userPass As Variant
Dim user As String
Dim pass As String
Dim connStr_ORA As String
Dim connStr_BASE As String
'用户
user = ""
'密码
pass = ""
If connType = "ORA" Then
'OLE DB驱动 ,主要适用于调用plsql 中的存在过程 生产
'获取 密码
userPass = Split(get_Db_Password.getDbPassword("annuity"), ",")
'用户
user = userPass(0)
'密码
pass = userPass(1)
connStr_ORA = "Provider=OraOLEDB.Oracle.1;User ID=" & user & ";Password=" & pass & ";Persist Security Info=True;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.89.24.56)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=Annuity)));Extended Properties=PLSQLRSet=1"
conn.Open connStr_ORA
ElseIf connType = "BASE" Then
'OLE DB驱动 ,主要适用于调用plsql 中的存在过程 生产
'获取 密码
userPass = Split(get_Db_Password.getDbPassword("base"), ",")
'用户
user = userPass(0)
'密码
pass = userPass(1)
connStr_BASE = "Provider=OraOLEDB.Oracle.1;User ID=" & user & ";Password=" & pass & ";Persist Security Info=True;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.89.24.54)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=dwprod)));Extended Properties=PLSQLRSet=1"
conn.Open connStr_BASE
ElseIf connType = "EXCEL" Then
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=excel 12.0;;Data Source=" & ThisWorkbook.FullName
End If
If connType <> "EXCEL" Then
'游标类型
conn.CursorLocation = adUseClient
End If
End Sub
'定义公共数据库返回结果集
Sub GetRs(ByVal sql As String)
'声明查询SQL字符
Dim strSql As String
'SQL赋值
strSql = sql
'返回结果游标类型,设置此参数在就能接收后面RS返回的结果集条数
rs.CursorLocation = adUseClient
'打开数据结果集
rs.Open strSql, conn, adOpenKeyset, adOpenStatic
'MsgBox GetRs.RecordCount
End Sub