Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Execute VBScript in perl to work on .xlsm

by suzun30 (Acolyte)
on Apr 06, 2013 at 00:06 UTC ( #1027232=perlquestion: print w/ replies, xml ) Need Help??
suzun30 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I need to execute a vbscript which opens a .xlsm file with some vba macro and does some processing in it and saves the file as another output file. I am able to execute the vbscript independently on cmd. However when I run it via my perl code, it gives error on the apache error log, that

it can't access the file specified in the path 'C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\TestWeb\\test.xlsm ' There are several possible reasons:\r, \x07 The file name or path does not exist.\r \x07 The file is being used by another program.\r \x07 The workbook you are trying to save has the same name as a currently open workbook.\r

My perl code is as follows

`cscript test.vbs arg1 arg2 filename.xlsm`; sleep(20); if(-e filename.xlsm){ print "File generated"; }else{ print "File Not found";
I am giving the sleep since the script takes some time to execute the macros and generate the .xlsm file. However nothing is working. I am invoking this from a webpage hosted on apache and on windows 2008 server. Alternatively, I tried usin Win32::OLE to access the excel
use Win32::OLE qw(in with); use Win32::OLE::Const ('Microsoft Excel'); my $excel = Win32::OLE->CreateObject('Excel.Application') || Win32::OL +E->new( 'Excel.Application', 'Quit' ); my $wrk_book = $excel->Workbooks->Open('C:/Program Files (x86)/Apache +Software Foundation/Apache2.2/htdocs/TestWeb/test.xlsm'); $excel->Run('CreateAdhocMDL',$arg1,$arg2, $filename ); $excel->{Visible} = 1; $excel->$wrk_book->SaveAs("C:/Program Files (x86)/Apache Software Foun +dation/Apache2.2/htdocs/LFWeb/$filename"); $excel->Close();
However, this gives error,"Can't locate object method "SaveAs" via package "Microsoft Excel", perhaps you forgot to load Microsoft Excel".

Appreciate any inputs. Thanks

Comment on Execute VBScript in perl to work on .xlsm
Select or Download Code
Re: Execute VBScript in perl to work on .xlsm
by Anonymous Monk on Apr 06, 2013 at 02:02 UTC

    One too many variables, one too many arrows

    $excel->$wrk_book->SaveAs(...

      I am not sure if that should be a problem. Still, I did try $wrk_book->SaveAs(). Still getting the same error. Appreciate any inputs on making it work the cscript way also, as it seems simple enough. It seems to not being able to locate the input file itself, which seems to indicate some issue with file path notation?? I tried all possible ways, forward slashes,backward slashes, double slashes. Apache seems to append an extra slash in the file path location. Is that a problem? Any way to work around it. Kindly let me know your opinions.

      Thanks a lot.

        I understood that the workbook object is not defined since the $wrk_book->Open("file") failed. But the same script when executed independently as a .pl file works fine. I am calling this functionality on my webpage. Apart from this there is no other difference in the code. Appreciate any inputs.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027232]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-10-23 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls