Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to write multiple values to a bookmark in Word Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
08-Nov-02
Category
OLE
Language
Delphi 5.x
Views
93
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How can I add rows at the end of a wordtable even when I have vertically merged 
cells? I always receive the error message "cannot access individual rows in this 
collection because the table has vertically merged cells"! The recorded word macro 
simple add a row by "selection.insertrows 1", but I have problems converting this 
into a Delphi statement (defining the right selection etc.).

Answer:

I've been automating MS Word, using bookmarks. Sometimes I need to write multiple 
values to one bookmark. I pass the values to the following routine as comma-text in 
the AValue parameter. It works fine with D5 using the Word97 unit and MS Word 2000 
executable. Hope it helps.

1   { ... }
2   FMSWord := CreateComObject(CLASS_WordApplication) as WordApplication;
3   { ... }
4   
5   procedure TLTWordDocHandler.PopulateListBookMark(const ABookMarkName:
6     string; const AValue: Widestring);
7   var
8     i: integer;
9     LBMName: OleVariant;
10    MoveUnit: OleVariant;
11    NumRows: OleVariant;
12    WorkingList: TStringList;
13  begin
14    LBMName := ABookMarkName;
15    FMSWord.ActiveDocument.Bookmarks.Item(LBMName).Select;
16    if FMSWord.Selection.Tables.Count = 0 then
17      raise Exception.Create(Format(sBookmarkNotInTable, [ABookmarkName]));
18    MoveUnit := wdCell;
19    NumRows := 1;
20    WorkingList := TStringList.Create;
21    try
22      WorkingList.CommaText := AValue;
23      for i := 0 to WorkingList.Count - 1 do
24      begin
25        FMSWord.Selection.TypeText(WorkingList.Strings[i]);
26        if not (i = (WorkingList.Count - 1)) then
27          FMSWord.Selection.MoveRight(MoveUnit, EmptyParam, EmptyParam);
28            {97 & 2000 compliant}
29      end;
30    finally
31      FreeAndNil(WorkingList);
32    end;
33  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC