Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 2003中的工作代码在Windows 7中引发运行时错误_Excel_Vba_Windows 7_Odbc_Adodb - Fatal编程技术网

Excel 2003中的工作代码在Windows 7中引发运行时错误

Excel 2003中的工作代码在Windows 7中引发运行时错误,excel,vba,windows-7,odbc,adodb,Excel,Vba,Windows 7,Odbc,Adodb,我已经在WindowsXP32位计算机上的MicrosoftExcel2003中创建了下面的宏,当我按下刷新按钮时,我的电子表格将按其应该的方式填充 但是,当我在用户计算机(windows 7计算机)上运行此操作时,32位和64位都会收到以下错误消息 “运行时错误“-2147467259(80004005)”: [Microsoft][ODBC驱动程序管理器]未找到数据源名称未指定默认驱动程序” 我猜您正在连接SQL Server。在混淆连接字符串时,您已经删除了可用于正确识别问题的任何信息。我

我已经在WindowsXP32位计算机上的MicrosoftExcel2003中创建了下面的宏,当我按下刷新按钮时,我的电子表格将按其应该的方式填充

但是,当我在用户计算机(windows 7计算机)上运行此操作时,32位和64位都会收到以下错误消息

“运行时错误“-2147467259(80004005)”: [Microsoft][ODBC驱动程序管理器]未找到数据源名称未指定默认驱动程序”


我猜您正在连接SQL Server。在混淆连接字符串时,您已经删除了可用于正确识别问题的任何信息。我怀疑您可能在其他PC上使用DSN,因为您甚至没有该字符串中的提供商。您可以在此处获得有关连接字符串的信息:

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