Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Win32::OLE excel application macro execution

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

Hi I am trying to run a macro from a .xlsm file via my webpage using the Win32::OLE module.
use Win32::OLE; use Win32::OLE::Const ('Microsoft Excel'); my $ex = Win32::OLE->new( 'Excel.Application', 'Quit' ); my $wkbk = $ex->Workbooks->Open('C:\test.xlsm') || die "could not open +:$!"; $ex->Run('test'); $ex->{Visible} = 1; $wkbk->SaveAs('C:\\SusTest2.xlsm') || die " could not save: $! " ; if(-e 'C:\SusTest2.xlsm'){ print "file exists"; } else{ print "file not created"; }
When I run this as a .pl file it works. However when I try to do the same on my webpage, it dies on the open() call from the workbook object. Any idea as to why it is happening? Also how to check cause for the error for the Open() method in Win32::OLE? I am not getting any error in the $! variable.

Replies are listed 'Best First'.
Re: Win32::OLE excel application macro execution
by Corion (Pope) on Apr 15, 2013 at 21:25 UTC
    This usually comes down to a permissions issue. Usually the user/system account your webserver and your script run as so not have the privileges to launch Excel, connect to OLE objects or read from arbitrary files or directories. You will have to consult with your server administrator how to best remedy this situation
      Hi , Thanks for the response. Would it not return a access denied error in that case? I am a part of the admin on this server and I am running the webpage with my userid logged in via sspi auth. So would it not give access to the files and folders per my authentication ? Kindly advise. Thanks,


        Corion is correct, this usually comes down to permissions.

        Try printing out the perms for all the files etc., you are accessing. And print the whole %ENV and anything else that comes to mind.

        The problem will probably be in the differences. Well it's a starting point. Get these out of the way and if it's still not working, come back with more details.


Re: Win32::OLE excel application macro execution
by NetWallah (Canon) on Apr 16, 2013 at 03:30 UTC
    If you are running this in a web server, the CGI::Carp module provides assistance in handling errors.

    For testing purposes, the following declaration will be invaluable (not for production use):

    use CGI::Carp qw(fatalsToBrowser);

                 "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
            -- Dr. Cox, Scrubs

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1028775]
Approved by Ratazong
Front-paged by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2018-01-17 13:26 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (200 votes). Check out past polls.