use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; use File::Find; use Win32::AbsPath qw(FixPath); use Win32::File; $VERSION=1.0; sub printhlp; @dirs = @ARGV; if (!@dirs or $ARGV[0] =~ m#^[-/][hj?]#) { printhlp(); exit; } foreach $dir (@dirs) { unless (-d $dir) {print "The directory \"$dir\" doesn't exist!\n\n";printhlp;exit;}; $dir = FixPath $dir; } $word = new Win32::OLE 'Word.Application','Quit' or die "Cannot start word!\n"; #$word->{visible}=1; find(\&foo,@dirs); sub foo { return unless /\.doc$/i; return if /^~\$/; my $file; ($file = $File::Find::dir.'\\'.$_) =~ s#/#\\#g; if (-e '~$'.substr($_,1)) { print "Already opened: $file\n"; return; } Win32::File::GetAttributes($file,$attr); if ($attr & READONLY) { Win32::File::SetAttributes($file,$attr - READONLY); } $doc = $word->Documents->Open($file) or print "Cannot open: $file\n"; if ($doc->PageSetup->{PaperSize} == wdPaperLetter) { $doc->PageSetup->{PaperSize} = wdPaperA4; $doc->Save(); print "Paper resized: $file\n"; } $doc->Close(); if ($attr & READONLY) { Win32::File::SetAttributes($file,$attr); } } sub printhlp { print "Letter2A4 directory ... Process the directories and change the paper size in all word documents from US Letter to A4. Version: $VERSION by Jenda Krynicky with help of Jan Dubois\n" }