Khalid,
I would assume that you need to go to Tools->Macro->Visual Basic Editor
You can use VBA from there. In VBA you may use ADO or something to connect to SQL Server. I did not do it myself with Excel but did with MS ACCESS.
I will be interested if someone will advise us here how to do it when refreshing Pivot Tables
Yelena