#!/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 = ; 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 set to H:\xxx if (-e "C:\\Program Files\\Microsoft Office\\Office11\\Winword.exe") { 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(wdDocumentsPath); 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(wdUserTemplatesPath); if ($templates_location =~ /H:\\MSOffice\\Templates/i) { print FH "Default user templates location is correctly set to ", $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 installed correctly.\n\n"; } }