KathyM has asked for the wisdom of the Perl Monks concerning the following question:

Hi, there. I have written a programme in Perl that is to extract the default file paths from Microsoft Word and Microsoft Excel, then write them to a file. However, the programme only works on the PC I created it on and I'm struggling to understand why. I realise there must be something different about the PC I created it on, but I don't know what. The PCs, while different models, are all running the same OS (Windows XP SP2), same version of Office (2003) and same version of Perl (ActiveState Perl 5.8.6) with all the same libraries installed.

On a PC other than the one I created it on, the programme starts, then exits with the message:

"Use of uninitialised value in print at line 54, <STDIN> line 1.

"Can't call method "Options" on unblessed reference at line 60, <STDIN> line 1."

Here is my code. The subroutine for Excel works on any machine, it's only the Word subroutine that doesn't, so I have omitted the code for the Excel routine in order to save space.

Any suggestions anyone has will be most appreciated.



#!/usr/bin/perl -w # Test file for Excel and Word # c:\perl\programs\ use strict; use Win32::OLE; use Win32::OLE::Const; $Win32::OLE::Warn = 3; # Main # Open file to pipe test results to open (FH, '>>C:\\Perl\\Programs\\test1.txt'); print "Please enter the name of the image being tested:\n"; my $image = <STDIN>; print FH "Test results for ", $image, " image.\n\n"; # Call subroutines for testing each application test_word(); test_excel(); # Subroutine to test Word sub test_word { use Win32::OLE; use Win32::OLE::Const; use constant wdDocumentsPath => 0; use constant wdUserTemplatesPath => 2; # Check Word exists on image, then check default file locations s +et to H:\xxx if (-e "C:\\Program Files\\Microsoft Office\\Office11\\Winword.ex +e") { my $Word = Win32::OLE::Const->Load("Microsoft Word"); $Word = Win32::OLE->GetActiveObject("Word.Application"); $Word->{visible} = 1; print FH "Microsoft Word testing:\n\n"; print FH "Microsoft Word opened successfully.\n\n"; my $printer = $Word->{ActivePrinter}; print FH "The default printer is set to ", $printer, ".\n\n"; # Check default documents location set to H:\My Documents\WWD my $document_location = $Word->Options->DefaultFilePath(wdDocume +ntsPath); if ($document_location =~ /H:\\My Documents\\WWD/i) { print FH "Default documents location is correctly set to ", +$document_location, ".\n\n"; } else { print FH "Default documents location is incorrectly set to " +, $document_location, ".\n"; print FH "It should be set to H:\\My Documents\\WWD.\n\n"; } # Check default templates location set to H:\MSOffice\Templates my $templates_location = $Word->Options->DefaultFilePath(wdUserT +emplatesPath); if ($templates_location =~ /H:\\MSOffice\\Templates/i) { print FH "Default user templates location is correctly set t +o ", $templates_location, ".\n\n"; } else { print FH "Default user templates location is incorrectly set + to ", $templates_location, ".\n"; print FH "It should be set to H:\\MSOffice\\Templates.\n\n"; } sleep 2; # Close Word $Word->Quit(); } else { print FH "Unable to open Word: check that Word has been install +ed correctly.\n\n"; } }