Solved

Vb.net word tables

Posted on 2014-09-09
3
410 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
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…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

816 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

8 Experts available now in Live!

Get 1:1 Help Now