none
New table added to Word Doc keeps merging with existing table RRS feed

  • Question

  • I am adding tables to a new Word document using VS 2012 vb.net. The first table adds okay but when I create the second table and position it directly below the first one (no line in between) Word keeps merging that table with the first one. I am adding the tables using the "endofdoc" bookmark location. 

    TableLocation = WordDocument.Bookmarks.Item("\endofdoc").Range
    NewTableObject = WordDocument.Tables.Add(TableLocation, 2, 4)

    If I add an empty line after the first table with

    TableLocation = WordDocument.Bookmarks.Item("\endofdoc").Range
    TableLocation.InsertBefore(vbCrLf)
    TableLocation = WordDocument.Bookmarks.Item("\endofdoc").Range

    and then add the second table, the table is added without merging. However, I don't want the empty line between the tables.

    What am I doing wrong here? I know there is some trick I'm missing with choosing the insertion point of my second table but I don't know what it is.

    Thanks,

    Darren
    Monday, June 9, 2014 4:04 PM

Answers

  • Hi Darren

    Basically, what you're running into is this simply how Word works. But you could format that empty paragraph with a very small font size (1 pt), which would make it almost invisible.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by dhaverstick Tuesday, June 10, 2014 3:31 PM
    Tuesday, June 10, 2014 3:15 PM
    Moderator

All replies

  • Hi Darren,

    After inserting the first table, you need to move the selection and type a blank row then insert the second table.

    It might be like this:

    Dim NewTableObject As Word.Table = doc.Tables.Add(TableLocation, 2, 4)
    NewTableObject.[Select]()
    wrdApp.Selection.MoveRight(Word.WdUnits.wdCharacter, 1)
    wrdApp.Selection.TypeParagraph()
    NewTableObject = doc.Tables.Add(wrdApp.Selection.Range, 3, 4)

    Hope this helps.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 10, 2014 9:32 AM
    Moderator
  • That solution works but also places a blank line between tables which I do not want.
    Tuesday, June 10, 2014 12:44 PM
  • Hi Darren

    Basically, what you're running into is this simply how Word works. But you could format that empty paragraph with a very small font size (1 pt), which would make it almost invisible.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by dhaverstick Tuesday, June 10, 2014 3:31 PM
    Tuesday, June 10, 2014 3:15 PM
    Moderator
  • Thanks, Cindy. That's not the elegant solution I was hoping for but it works.

    Darren

    • Marked as answer by dhaverstick Tuesday, June 10, 2014 3:30 PM
    • Unmarked as answer by dhaverstick Tuesday, June 10, 2014 3:31 PM
    Tuesday, June 10, 2014 3:30 PM