in reply to Win32 ->Replacement->{Text} more than 255 characters

any ideas on an alternative approach

You could search for and delete the token then insert the new text

#!perl use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 3; my $word = Win32::OLE->new('Word.Application', 'Quit') or die; $word->{Visible} = 1; $word->{DisplayAlerts} = 0; my $doc = $word->Documents->Open({FileName => "c:/temp/Word.doc"}); my $sel = $word->Selection; $sel->Find->{Forward} = 1; $sel->Find->{MatchWholeWord} = 1; for my $n (1..2){ $sel->Find->{Text} = '##TOKEN'.$n.'##'; $sel->Find->Execute; $sel->Delete; $sel->InsertAfter("($n) This is line 1 of some new text that is more + than 255 characters. This is line 2 of some new text that is more than 255 characters. This is line 3 of some new text that is more than 255 characters. This is line 4 of some new text that is more than 255 characters. This is line 5 of some new text that is more than 255 characters. This is line 6 of some new text that is more than 255 characters. This is line 7 of some new text that is more than 255 characters. This is line 8 of some new text that is more than 255 characters."); $sel->MoveDown({Count=>1}); }; $doc->SaveAs({FileName => 'c:/temp/Word1.doc'}); $doc->Close();
poj

Replies are listed 'Best First'.
Re^2: Win32 ->Replacement->{Text} more than 255 characters
by 3dbc (Monk) on Jan 25, 2017 at 16:48 UTC
    Thanks so much Monks for welcoming me back. Couldn't resist using my old account because I'm only 100 points away from being titled a Monk! I think this last post is exactly what I was looking for... I'm not sure you can do multiple replacements with that win32 ole method? Giving it a shot now. THANK YOU

    Also wanted to provide the error message returned in case anyone is searching for this on this site or through google by the error code.

    Win32::OLE(0.1712) error 0x80020009: "Exception occurred" in PROPERTYPUT "Text" at evolveIT2.pl line 193. OLE exception from "Microsoft Word": String parameter too long.