Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8215907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:56:43+00:00 2026-06-07T11:56:43+00:00

I have some Delphi code that selects a bookmark in Word and then creates

  • 0

I have some Delphi code that selects a bookmark in Word and then creates a table. My problem is that there is a title at the top of the page that when I select the range also gets selected and when my table is created the title is overwritten. How can I just select the range after my bookmark to add my table so that my title is preserved?

R := WordApp.ActiveDocument.Bookmarks.Item('bmStartSecond').Range;
R.Select;
TableFormat(WordDoc, intCounter + 10);

function TableFormat(Adocument : variant; intNumRows : integer): variant;
var
wrdSelection: variant;
begin
  wrdSelection := WordApp.Selection;
  Adocument.Tables.Add(Range:=wrdSelection.Range, NumRows:=intNumRows, NumColumns:=3);
  Adocument.Tables.Item(1).Columns.Item(1).SetWidth(InchestoPoint(2.5),0);
  Adocument.Tables.Item(1).Columns.Item(2).SetWidth(InchestoPoint(2.25),0);
  Adocument.Tables.Item(1).Columns.Item(3).SetWidth(InchestoPoint(2.75),0);
  wordDoc.Tables.Item(1).Cell(Row:=1, Column:= 1).Range.Text := 'Offense:';
  wordDoc.Tables.Item(1).Cell(Row:=1, Column:= 2).Range.Text := 'Date & Place:';
  wordDoc.Tables.Item(1).Cell(Row:=1, Column:= 3).Range.Text := 'Disposition:';

  TableFormat := Adocument;
end;

Thanks,
Leslie

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:56:45+00:00Added an answer on June 7, 2026 at 11:56 am

    This adds a table after a named bookmark. You should be able to adapt it to your needs. (Your code is from decades ago, BTW – modern Delphi uses Result to indicate return values instead of FunctionName :=. Result is an automatically-created variable of the proper type for the function.) Tested using Delphi 2007, Office XP components, on Windows 7 and an Office 2007 installation.

    procedure TForm1.AddTable;
    const
      Line1 = 'January,February,March';
      Line2 = '31,28,31';
      Line3 = '31,59,90';
    var
      R, Direction, Separator, BookmarkName, TableFormat, Cols: OleVariant;
    begin
      BookMarkName := 'bmTest';
      R := WordApp.ActiveDocument.Bookmarks.Item(BookmarkName).Range;
      Direction := wdCollapseEnd;
      R.Collapse(Direction);
      R.InsertAfter(Line1);
      R.InsertParagraphAfter;
      R.InsertAfter(Line2);
      R.InsertParagraphAfter;
      R.InsertAfter(Line3);
      R.InsertParagraphAfter;
      Separator := ',';
      TableFormat := wdTableFormatGrid1;
      R.ConvertToTable(Separator);
    
      // Cleaner to grab a reference to the table columns, and use
      // it instead of the long reference every time.
      Cols := WordApp.ActiveDocument.Tables.Item(1).Columns;
      Cols.Item(1).SetWidth(WordApp.InchesToPoints(2.25), wdAdjustNone);
      Cols.Item(2).SetWidth(WordApp.InchesToPoints(3.5), wdAdjustNone);
      Cols.Item(3).SetWidth(WordApp.InchesToPoints(2.75), wdAdjustNone);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some legacy code that compiles in Delphi 6. There are plans to
In some legacy Delphi code that I need to port to C#, I have
We have some ancient Delphi code (might have even originated as Turbo Pascal code)
I have some colors that seem to come from a Delphi TColor variable (e.g
I have several Delphi programs that maintain connections to a database (some Oracle, some
I have bat-file, that make some operations. How to run this file from Delphi
I have some code that starts a process and hooks up an event handler
I have some code that does custom drawing. Basically it is form fill program
I have Delphi 2007 code that looks like this: procedure WriteString(Stream: TFileStream; var SourceBuffer:
I have some delphi code which, given a list of items, calculates the total

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.