Options

Word Automation Puts Table Over the Document Title

Matt.HillMatt.Hill Member Posts: 32
I'm trying to create a report that is passed to Word. Each page is titled with the Customers name, and there is a table below this which details their current order.

However, when the table is produced, having placed the Customers name at the top of the page and moved down two lines to place the table at that point the cursor is moved back to the top of the page and the title is over-written with the table!

How to I get the table to be inserted at the cursor's current line...?

The declarations are:
WrdApp.Documents.Add; // new blank page
WrdRange := WrdApp.ActiveDocument.Range;
wrdSelection := WrdApp.Selection;
WrdRange.Font.Size := 10;


The heading is thus:
wrdSelection.Font.Italic(1);
wrdSelection.TypeText('Customer: ' + Customer."No." + ' ' + Customer.Name);
wrdSelection.Font.Italic(0);
wrdSelection.TypeParagraph;
wrdSelection.TypeParagraph;

I'm using the following to generate the table:
wrdTable := WrdRange.Tables.Add(WrdRange,(Rows + 1),Collumns);


Thanks!

Comments

  • Options
    janpieterjanpieter Member Posts: 298
    Lucky gues : Cant you do

    wrdSelection.Tables.Add

    instead of

    wrdRange.Tables.Add


    Regards, Jan-Pieter
    In a world without Borders or Fences, who needs Windows and Gates?
  • Options
    Matt.HillMatt.Hill Member Posts: 32
    First thing I tried, and gives the same result....
  • Options
    janpieterjanpieter Member Posts: 298
    And this ... ? The first parameter of the add function looks like a pointer to some place in the document. Try changing that in various ways. I dont think the add function takes the cursor position at all.

    wrdTable := WrdSelection.Tables.Add(wrdSelection.Range, (Rows + 1), Collumns);

    You could also make a template document, place a table on it and open this. Then you make a pointer to the table like this:

    wrdTable := WrdSelection.Tables.Item(0);

    I think that will be a lot easier.

    You can also try recording a macro in VBA. Then add the table while recording. When done look in the macro designer (ALT+F11) and steal the code it has generated for you. Try to translate it to C/AL.


    Good luck
    In a world without Borders or Fences, who needs Windows and Gates?
Sign In or Register to comment.