Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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 open_excel_7.pl line 54, <STDIN> line 1.

"Can't call method "Options" on unblessed reference at open_excel_7.pl 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.

Thanks,

Kathy.

#!/usr/bin/perl -w # Test file for Excel and Word # c:\perl\programs\open_excel_7.pl 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"; } }

In reply to Win32::OLE and Word by KathyM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-01-30 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?