#!/usr/bin/perl -w use strict; use Win32::OLE; use Win32::OLE::Const; my $wd = Win32::OLE::Const->Load("Microsoft Word 14.0 Object Library"); printf "wdRed = %s\n", $wd->{wdRed}; printf "wdGreen = %s\n", $wd->{wdGreen}; my $document_name = 'C:\Users\boss\worddoc.doc'; my $word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application','Quit') or die Win32::OLE->LastError(); my $document = $word->Documents->Open($document_name) or die Win32::OLE->LastError(); my $paragraphs = $document->Paragraphs(); my $n_paragraphs = $paragraphs->Count(); for my $p (1..$n_paragraphs) { my $paragraph = $paragraphs->Item($p); my $text = $paragraph->Range->Text(); my $font = $paragraph->Range->Font(); if ($text =~ /interviewer/i) { print "$text\n\n"; $font->{'ColorIndex'} = $wd->{wdGreen}; } else { $font->{'ColorIndex'} = $wd->{wdRed}; } } $document->Save; $document->close;