Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am performing a job from SQL server agent with a powershell command.

It was running fine a couple of days back.. there is no change in the script.

The script is also working fine if i run it via powershell.exe

Now when i run the same job its not working.... Below is the script which does a simple job of refreshing data via a macro an excel n save it as another workbook.

i get this error

A job step received an error at line 2 in a PowerShell script. The corresponding line is '$Excel = New-Object -ComObject Excel.Application'. Correct the script and reschedule the job

Script

$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true
$Excel.DisplayAlerts = $false
############## Working with Workbooks #############

$Excel.Workbooks.Open("C:\Users\dashboard\Dropbox\SMX Data\India\Data Flat Files\IntCreditors.xlsm")
$Excel.run("AutoUpdate")
$Excel.Workbooks.item("IntCreditors.xlsm").SaveAs("C:\Users\dashboard\Dropbox\SMX Data\India\Data Flat Files\IntCreditors.xlsm")
$Excel.Workbooks.Close()
$Excel.Quit()
Get-Process excel | Stop-Process -Force
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)

Please help

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.