Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( [id://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 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"; } }

In reply to Win32::OLE and Word by KathyM

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others contemplating the Monastery: (5)
    As of 2024-07-18 07:30 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found

      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.