my $doc = $Word->Documents->Open($_[0]) || die("Unable to open document ", Win32::OLE->LastError()); # Open document #my $doc = $MSWord->Documents->Open({FileName=>$_[0]}); # Exit nicely if we couldn't open doc return unless $doc; # Content object my $content=$doc->Content; #my $selection = $word->Selection; print "Finding Tokens...\n"; # Find object my $find=$content->Find; $find->ClearFormatting; $find->{Text}="##TOKEN_REPLACE##"; $find->Replacement->ClearFormatting; $find->Replacement->{Text}=$cant_be_more_than_255 #### if (length($service_screens) > 255) { print "These are $service_screens string is over 255 \n\n"; $find->ClearFormatting; $find->{Text}="##TOKEN_REPLACE##"; $find->Replacement->ClearFormatting; $find->Replacement->{Text}="Service Screens"; #$doc->ActiveWindow->Selection->MoveDown(wdLine,1); #$doc->ActiveWindow->Selection->TypeText("Can't write scalar because it's over 255 chars??"); $find->Execute({Replace=>$wd->{wdReplaceAll},Forward=>$wd->{True}}); } else { $find->ClearFormatting; $find->{Text}="##TOKEN_REPLACE##"; $find->Replacement->ClearFormatting; $find->Replacement->{Text}=$service_screens; #$doc->ActiveWindow->Selection->MoveDown(wdLine,1); #$doc->ActiveWindow->Selection->TypeText("This line should be after the Service screen"); $find->Execute({Replace=>$wd->{wdReplaceAll},Forward=>$wd->{True}}); }