Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Was "How to insert text in Word Doc" 3

Status
Not open for further replies.

greadey

Technical User
Oct 25, 2001
231
GB
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.
 
Nice goin. Returned the
star.gif
.

--
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top