2

I am trying to run Excel macros from a Jenkins Windows service on Windows 7 64-bit VM. I have a batch file that specifies VBS files. Then in the VBS files, the Excel macros are listed. The batch files run fine locally, but when I run it from Jenkins, I get the following error:

Microsoft VBScript runtime error: ActiveX component can't create object: 'Excel.Application'

The error seems to occur on each instance of the following in the VBS files:

Set xlApp = CreateObject("Excel.Application")

Just searching around, I see that lots of other people have had problems with the version of cscript being used to execute the VBS files. On 64-bit computers, it seems that the 32-bit version of cscript must be used. But no matter how I try to force that version of cscript to be used, Jenkins seems to ignore it and display the same error, which makes me think that the cscript version is not the cause of my error.

I do have macros enabled in Excel and checked the ActiveX settings too. Like I said, double-clicking the batch file, everything works fine. There's gotta be something weird Jenkins is doing to cause the problem.

Any ideas?

MisterBic
  • 307
  • 5
  • 18
kakronst
  • 36
  • 1
  • 3
  • Is your Office install 32-bit or 64-bit ? – Tim Williams Jun 01 '16 at 19:12
  • I am facing the similar issue,I ran cscript .vbs but got the following error: Caused: java.io.IOException: Cannot run program "/bin/sh" (in directory "C:\Jenkins\workspace\generateParams"): CreateProcess error=2, The system cannot find the file specified. My vbs script open an excel file -->runs a macro-->closes it.The excel file and vbs script is at the same location,but is different from jenkins workspace.Is this the cause of issue? – salsinga Feb 02 '18 at 09:00
  • Late but there is a similar question [Jenkins QC plugin Can't create TDConnection Object ](https://stackoverflow.com/questions/18319573/jenkins-qc-plugin-cant-create-tdconnection-object) which points to a [workaround](http://www.sqaforums.com/showflat.php?Number=479531) – Ben1980 Apr 16 '18 at 15:18

2 Answers2

0

Try using

Set xlApp = GetObject("Excel.Application")

On closer reading of your question, it seems like you may have trouble with executables. Hmmm, can you actually give a full command line, soo instead of run/double click foo.vbs something like script.exe foo.vba. I made up script.exe but you should get the point, why not specify the executable?

I have seldom heard of Jenkins, care to provide any documentation links you think maybe relevant to this issue. It's all useful for future stackoverflower meeting the same problem.

S Meaden
  • 8,050
  • 3
  • 34
  • 65
0

I use the following script to open excel and kick off a macro. I typically launch a WSF file that calls the below code via CSCRIPT from Jenkins/Batch File/Task Scheduler/etc. Works like a charm (Make sure you have Excel installed on the system this is running on.)

Set Excel = CreateObject("Excel.Application")
Set Workbook = Excel.Workbooks.Open(excelfile)
Excel.Application.Visible = True
Excel.Application.DisplayAlerts = True
Excel.Application.Run macroname
Excel.ActiveWorkbook.Close
Set Workbook = Nothing
Set Excel = Nothing