Excel 2003 How to pass params to SQL sproc (pivot based on external source)?
I created Excel 2003 pivot table which uses External source and SQL 200开发者_开发知识库8.
I wrote in the query:
exec mysproc '20110726', '20110727'
and it works fine. However I need to be able to pass the dates taken from Excel cells.
What is the cleanest/shortest solution?
Found the answer. Added button attached to the following sub:
Sub RefreshPivotQuery()
Dim d1 As String
Dim d2 As String
d1 = Format(Sheets("Main").Range("Date1"), "yyyymmdd")
d2 = Format(Sheets("Main").Range("Date2"), "yyyymmdd")
Dim ws As Worksheet
Set ws = Sheets("Pivot")
ws.PivotTables(1).PivotCache.CommandText = "exec mysproc '" + d2 + "', '" + d1 + "'"
End Sub
精彩评论