Excel 2010 vs Excel 2013 VBA存储过程

我有一个电子表格,从而调用SQL Server存储过程并返回数据。 在Excel 2010中工作100%,已经完成了几个月。 但是,对于Excel 2013上的某些用户,它不会返回所有数据 – 它只是通过0。 这是我的代码:

Sub Button10_Click() Set con = New ADODB.Connection Set cmd = New ADODB.Command Set rs = New ADODB.RecordSet Sheets("Customer").Visible = True 'Unprotect worksheet Worksheets("Customer").Unprotect Password:="*******" ' remove and re-add auto filter Sheets("Customer").AutoFilterMode = False Sheets("Customer").Range("A4:AO4").AutoFilter Application.DisplayStatusBar = True Application.StatusBar = "Contacting SQL Server..." ' Remove any values in the cells where we want to put our Stored Procedure's results. With Sheets("Customer") .Rows(5 & ":" & .Rows.Count).Delete End With ' Log into our SQL Server, and run the Stored Procedure con.Open "Provider=SQLOLEDB;Data Source=*********;Initial Catalog=**********;Integrated Security=SSPI;Trusted_Connection=Yes;" cmd.ActiveConnection = con Application.StatusBar = "Running stored procedure..." '===== Check if the user has ticked the 'Include Current Month Totals checkbox ==== If Range("$M$1") = True Then 'include current month in totals cmd.CommandText = "usp_Customer_Lvl1_Current_Month_INC" Else 'do not include current month in totals cmd.CommandText = "usp_Customer_Lvl1_Previous_Month_INC" End If Set rs = cmd.Execute(, , adCmdStoredProc) '========== Sheets("Customer").Range("A5").CopyFromRecordset rs Application.Goto Reference:=Worksheets("Customer").Range("A5") 'protect worksheet Worksheets("Customer").Protect Password:="***********", AllowFormattingCells:=True, AllowFiltering:=True '============= rs.Close Set rs = Nothing Set cmd = Nothing con.Close Set con = Nothing Application.StatusBar = "Data successfully updated." End Sub 

它必须是在VBA中的东西。 数据在SQL和Excel 2010中有 – 有什么想法?

我解决了。 我从文本框中获取一个值。 在Excel 2010中,我只是使用下面的内容:

如果Range(“$ M $ 1”)= True那么

但是,在Excel 2013中,您似乎也需要参考工作表:

如果表格(“Home”)。Range(“$ M $ 1”)= True那么

无论如何,现在包括工作表名称意味着它的工作原理。