Solved

Vb.net word tables

Posted on 2014-09-09
3
399 Views
Last Modified: 2014-10-31
Hi,

I have an application I'm using to modify bookmarks in my word document, I was wondering if it was possible to edit a table from vb.net so that I may delete specific cells and rows, certain cells also have split cells... Basically I need to remove everything that has no text in it, would this be possible? It's only one table with multiple rows and split cells

Thank you
0
Comment
Question by:FCapo
  • 2
3 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40313036
It is possible to edit tables in code.

However, dealing with tables with an inconsistent number of cells in a row can be tricky, as can tables with an inconsistent number per column. For tables with inconsistency in both directions it is trickiness squared.

Can you post a sample document (redacted if necessary)?
0
 

Author Comment

by:FCapo
ID: 40314708
Yes of course,

here is a sample word document of the table I'm referring too, as you can see it's a table with a maximum of 3 rows, the second and fourth column are split into 4 more rows...

from my program I use bookmarks to replace the "text" with strings from my application. Most of the time the user will not need all 3 rows, and also he may not need all 4 cells split in the second and fourth column. I could always leave it up to the user to the delete the extra "left over" rows and cells, but I figure there may be a better way,

Thank you
sample.doc
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40315239
Presumably you would need the corresponding cell in column 5 to be deleted as well.

This is actually VBA code, but it shows the idea:
Sub FillBookMark(wdDoc As Word.Document, strBookmarkName As String, strText As String, tbl)
    Dim cl As Word.Cell
    If Len(strText) = 0 Then
        If wdDoc.Bookmarks(strBookmarkName).Range.Cells.Count = 1 Then
            wdDoc.Bookmarks(strBookmarkName).Range.Cells.Delete ShiftCells:=wdDeleteCellsEntireRow
        End If
    Else
        wdDoc.Bookmarks(strBookmarkName).Range.Text = strText
    End If
End Sub

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now