当我运行以下代码时,会收到一个错误提示:"运行时错误'1004': 应用程序或对象定义的错误"
当我选择调试时,会突出显示以下行:.Refresh BackgroundQuery:=False
querystr = "SET NOCOUNT ON" & Chr(13) & _
"SELECT CSD.StoreNo AS 'StoreNo',SUM(CSD.Amount) as totalSales " & Chr(13) & _
"INTO #SalesOfTheStores " & Chr(13) & _
"FROM Purchase.dbo.CashsheetDetail as CSD " & Chr(13) & _
"INNER JOIN Purchase.dbo.CashsheetHeader as CSH on CSH.TransferID = CSD.TransferID and CSH.StoreNo = CSD.StoreNo " & Chr(13) & _
"WHERE CSD.Comments = 'Total Gross Sales' AND CSH.DayendDate between '" & StartDate & "' And '" & EndDate & "' " & Chr(13) & _
"GROUP BY CSD.StoreNo; "
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=" & Div & "DBL01\SR;UID=" & User & ";APP=Microsoft Office 2003;WSID=" & PC & ";DATABASE=Purchase;Trusted_Connection=Yes" _
, Destination:=Range("A1"))
.RefreshStyle = xlOverwriteCells
.CommandText = querystr
.Refresh BackgroundQuery:=False
End With