Can't call method "Documents" on unblessed reference

Posted on 2008-10-21
Last Modified: 2013-12-25

I have a cgi script that I run on two web servers that uses Word OLE to open up a word doc, convert it to rtf and then we run some Omnimark on it.

It runs fine via the browser on these two web servers.

I have just tried to run this on our 3rd disaster recovery server and it gives me the following error:

[Tue Oct 21 15:29:57 2008] [error] [client] Can't call method "Documents" on unblessed reference at D:/Program Files/Apache Group/Apache2/cgi-bin/upload/ole.cgi line 41, <DATA> line 164.\r

Line 41 is:

$WORD->Documents->Open($filein) or print  "WARNING: Unable to open document " . Win32::OLE->LastError();

Now. If I run this script via the command line it works, but if I run it via a browser it doesn't. AS I said, on the other two servers it runs fine either via command line or the browser and I have run out of ideas!

I have stripped the script down to the bare basics for testing:

use strict;

use warnings;

use Win32::FileOp;

use Win32::OLE;

use Win32::OLE::Const 'Microsoft Word';

sub ConvertToRTF;

sub CheckOLE;

my $filein;

my $fileout;

my $WORD;



sub CheckOLE {


	if (Win32::OLE->LastError()) {

		print "OLE error !!! \n";

		my $err = Win32::OLE->LastError();

		print $err."\n";





sub ConvertToRTF {


my $filein = 'D:\\RTFtoXML\\rtf\\Test.doc';

my $fileout = 'D:\\RTFtoXML\\rtf\\Test.rtf';

print "Content-type: text/html \n\n";			# print the http header

	print "The file out is $fileout<br>";

$WORD = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit');

   $WORD->{'Visible'} = 1;         # if you want to see what's going on

	$WORD->Documents->Open($filein) or print  "WARNING: Unable to open document " . Win32::OLE->LastError();



		FileName	=> $fileout,

		FileFormat	=> wdFormatDocument,     # .doc format

		FileFormat	=> wdFormatRTF,          # .rtf format       

		LockComments=> 0,

		Password 	=>"",

		AddToRecentFiles=> 0,

		EmbedTrueTypeFonts => 0,

		SaveNativePictureFormat => 0,			});



	undef $WORD;

	print "<p>Finished RTF conversion, please wait...<br><br><p>";


Open in new window

Question by:Hedley Phillips
  • 3
  • 2
LVL 39

Assisted Solution

Adam314 earned 250 total points
Comment Utility
Is Word installed on this third server?

The problem is here:
    $WORD = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit');
The $WORD is not being set to an object.  You could add this:
    die "Could not create WORD object\n" unless $WORD;

LVL 14

Author Comment

by:Hedley Phillips
Comment Utility

thanks for your reply.

Word is installed on this server and if I run this script from the command line I see it opening up and then closing and I get an rtf file (I have $WORD->{'Visible'}  set to 1 so it is visible).

It is only when it is run via the browser that it fails saying I haven't been to church.
LVL 39

Expert Comment

Comment Utility
Does the web server user have permission to start word?
Is there anything in your error log?
LVL 14

Accepted Solution

Hedley Phillips earned 0 total points
Comment Utility
Fixed it!

I rebooted the server and it works fine.

Don't know why that would stop it running from the browser but allow it on the command line but there we are.

LVL 39

Expert Comment

Comment Utility
The tried and true "reboot" solution... used to be very common, but still has it's place.

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now