Many organization have lots of Excel reports and pivot tables whose data comes from SQL Server. As data on the backend database changes you would need to repopulate your excel books with updated information. Doing it by hand can be very tedious manual process for the reporting analyst and there are ways to automate it. The simplest way is to create a SQL Agent job which refreshes your books on a scheduled basis. VBScript below does exactly that. Just add a step to your refresh job for every report you want to refresh substituting "<path to your excel file>" with location of your excel file on some file share.
Set oWorkBook = oExcel.Workbooks.Open("<path to your excel file>")
Now you saved yourself a whole lot time and can start working on more interesting things!
Cheers, -Yuriy
Script below
Function Main()Dim oExcelDim oWorkBookDim oWorksheetDim oPivotTableDim IStartedExcel On Error Resume NextSet oExcel = GetObject("Excel.Application") 'will attach to an existing instance if it is there.oExcel.Quit 'Instantiate excel object; disable alert messagesSet oExcel = CreateObject("Excel.Application")oExcel.DisplayAlerts = false 'when debugging set visible = trueoExcel.visible = true
'open workbook we wish to refreshSet oWorkBook = oExcel.Workbooks.Open("<path to your excel file>")oWorkbook.EnableConnections oWorkbook.RefreshAlloExcel.CalculateUntilAsyncQueriesDoneoWorkbook.SaveoWorkBook.Close oExcel.QuitSet oExcel = Nothing 'Main = DTSTaskExecResult_Success
End Function