SQL Server/VBS Script to Export to Excel

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
174
This may be beyond the scope of this board, but thought I'd give it a shot --

I have a VB Script that connects to a SQL DB, an exports a query in Excel. I can run it from the command line and it executes perfectly:
cscript "\\network\folder\folder\"VBScript.vbs

When I create a SQL Server Agent Job to execute the same script, however, it fails. The type is 'Operating System (CmdExec)' and I'm running it with a Proxy I created -- the proxy is based on my own credentials. I'm simply calling the vb script that I have saved on a network drive, exactly as I call it from the command line. This method works for simpler scripts, which copy, move, or rename files. But it fails with this script, as it cannot seem to create the instance of Excel. I get the following error --

Microsoft VB Script Error: Active X component can't create object 'Excel.Application' -- referencing the following line of code:
OApp = CreateObject("Excel.Application")

Again -- this works perfectly fine when I run it from the command line, but errors out here. Perhaps there's something basic I'm missing. Any thoughts would be greatly appreciated. Thanks!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
It’s very unlikely that you’ll have excel installed on your server - remember that the agent job is running as the database user and unless Excel is installed on your sql server then you can’t create an instance of it
 
Upvote 0
Thank You! Yes -- it's a shame I can't create the job I want using entirely VB Script, but I was able to get an export to excel to work with an SSIS Package -- so I'm creating the job I'm after using a combination of VB Scripts, T-SQL Scripts, and SSIS Packages. Hopefully this thread will help someone else trying to do the same thing.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top