We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Including an optional table in Word document


I have a word document which has a table in it that should not be displayed if there is no data in the table.

I think the way to achieve this would be to put the table in a bookmark and then remove the data in the bookmark if there is nothing to display.

I have attached a document for reference.

Here is a sample of code I have in VB to remove the table.

Dim doc As Document = New Document(templatePath)

doc.MailMerge.RemoveEmptyParagraphs = True

doc.Range.Bookmarks("LipidBookmark").Text = ""



'Save the document

doc.Save(LetterName, SaveFormat.Doc, SaveType.OpenInWord, Response)

However the table will always show in my resulting document.

The version of Words that I am using is

Any clues to where I have gone wrong would be greatly appreciated.


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I think that you can try using the following code:

Dim doc As Document = New Document("in.doc")

'Get table

Dim table As Node = doc.Range.Bookmarks("LipidBookmark").BookmarkStart.GetAncestor(NodeType.Table)

'Remove table if it exists

If (Not table Is Nothing) Then


End If

'Save the document


I hope this helps.

Best regards.

Hello Alexey,

Thank you for your response.

I was just coming back to the forum now to say that I managed to achieve what I wanted with TableStart/TableEnd.

I will keep your suggestion for future reference. Thanks once again!


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

It is nice that you already found solution.

Best regards.