-
2
- #1
Following a question about how to inset text into a word document at a specific bookmark I followed a thread given to me by NaChoz (many thanks). As seems to be the general opinion there was nothing concrete anywhere on this particular subject, however there was enough info to help me start looking in the right places so I came up with this little test snippet for those of you who are interested
use strict;
use Win32::OLE;
my $wd = Win32::OLE->new('Word.Application');
$wd->{'Visible'} = 1;
$wd->Documents->Open("C:\\test3.doc"
;
my $doc = $wd->ActiveDocument;
$doc->Bookmarks("BKMK1"
->Select;
$wd->Selection->TypeText("Bloody Done it"
;
$doc->Bookmarks("BKMK2"
->Select;
$wd->Selection->TypeText("YEEEEEEEEs"
;
It's not got the robustness of a full blooded Win32::OLE script but it proves the point. The key thing here is knowing where the desired properties and methods are in the word object heirachy i.e. notice that the selection of the bookmark is made at the ActiveDocument level, however to get at the selection itself you have to go up one level to the Word.Application level.
use strict;
use Win32::OLE;
my $wd = Win32::OLE->new('Word.Application');
$wd->{'Visible'} = 1;
$wd->Documents->Open("C:\\test3.doc"
my $doc = $wd->ActiveDocument;
$doc->Bookmarks("BKMK1"
$wd->Selection->TypeText("Bloody Done it"
$doc->Bookmarks("BKMK2"
$wd->Selection->TypeText("YEEEEEEEEs"
It's not got the robustness of a full blooded Win32::OLE script but it proves the point. The key thing here is knowing where the desired properties and methods are in the word object heirachy i.e. notice that the selection of the bookmark is made at the ActiveDocument level, however to get at the selection itself you have to go up one level to the Word.Application level.