我已经在Windows XP 32位计算机上的Microsoft Excel 2003中创建了下面的宏,当我按下刷新按钮时,我的电子表格会按原样填充。
然而,当我在用户机器上运行这是Windows 7机器时,32位和64位我都收到以下错误消息
“运行时错误'-2147467259(80004005)': [Microsoft] [ODBC驱动程序管理器]未找到数据源名称未指定默认驱动程序“
Private Sub CommandButton1_Click()
Dim cmd As New ADODB.Command
Dim conn As ADODB.Connection
Dim prm As ADODB.Parameter
Dim strConn As String
Dim strSQL As String
Dim Rst As ADODB.Recordset
Dim WSP As Worksheet
Dim lastRow As Long
Dim ranges As range
strConn = "Data Source=;Initial Catalog=;User Id=;Trusted_Connection=False;"
Set conn = New ADODB.Connection
Set WSP = Worksheets("KPI")
lastRow = WSP.Cells.SpecialCells(xlCellTypeLastCell).Row
Set ranges = WSP.range("A6", WSP.Cells(lastRow, "K"))
ranges.Clear
conn.Open strConn
Set cmd = New ADODB.Command
cmd.CommandText = "dbo.returns_kpi_data"
cmd.CommandType = adCmdStoredProc
cmd.ActiveConnection = conn
cmd.Parameters.Refresh
cmd.Parameters("@OrderDate1").Value = WSP.range("G3", "G3")
cmd.Parameters("@OrderDate2").Value = WSP.range("I3", "I3")
'Execute the Stored Procedure
Set Rst = cmd.Execute
range("A6").CopyFromRecordset Rst
'Close the connection
conn.Close
End Sub
答案 0 :(得分:3)
我猜您正在连接到SQL Server。在混淆连接字符串时,您已删除了可用于正确识别问题的任何信息。我怀疑您可能在其他PC上使用DSN,因为您甚至没有该字符串中的提供程序。您可以在此处获取有关连接字符串的信息:http://www.connectionstrings.com/