• Hi All

    i am trying to execute VB script to refresh my excel files.. using Vbscript file through SQL Agent job step.

    i have copied VBscript in a file with the extension RefreshExcel.vbs kept in C:\RefreshExcel.vbs

    my Excel file (ReportFile1.xlsx) , is kept under this folder (F:\Reports\Reports\)

    Below is the script used inside the file (RefreshExcel.vbs)

    //---Script code-----------------------------------------------------------------

    Dim objXL, objWB

    Dim FileLocation, FileName

    On Error Resume Next

    'lgnConn = 1

    FileLocation = "F:\Reports\Reports"

    Set objXL = CreateObject("Excel.Application")

    objXL.DisplayAlerts = False

    FileName = "ReportFile1.xlsx"

    'MsgBox (FileLocation & "/" & FileName)

    Set objWB = objXL.Workbooks.Open(FileLocation & "/" & FileName)

    objWB.EnableConnections

    objXL.CalculateUntilAsyncQueriesDone

    objWB.RefreshAll

    objXL.CalculateUntilAsyncQueriesDone

    objWB.RefreshAll

    objXL.CalculateUntilAsyncQueriesDone

    objWB.Save

    objWB.Close

    Set objWS = Nothing

    Set objWB = Nothing

    objXL.Quit

    Set objXL = Nothing

    'MsgBox ("Refresh Completed")

    ---------------------------------------------------------------------------------------------------//Script complete

    Now when i am trying to call this script file in SQL agent job step as Type(job Properties) cmdExec(OperatingSystem)

    cscript "C:\RefreshExcel.vbs"

    Issue: job step executed succesfully ,,but without performing any refresh on the excel. So i am not understandig what is going wrong. the same script file work when i am calling it through a batch file (window scheuler task). But it doesnt support to run the file "when user is not logged in"

    that is why i want to refresh my excel file through sql agent ,which can be scheduled to any time and cab be run as SQL agent credentials.

    Can you please help me on this ...i have tried all the option but nothing working .. found hope by seeing your solution.

    Thanks in advance.

    Please help me. 🙁