Solved

Lines between word tables in VB.NET

Posted on 2015-01-22
6
335 Views
Last Modified: 2015-01-26
Experts, I am working with Word tables in VB.Net. I have three tables on one page. The only way I could figure out how to leave one table and insert a new table was to use this little bit of code here. But this leaves me with a line between the tables. Is there a way to create a table directly after the previous table? It would look like one table but would be multiple tables.

                        oWord.Selection.EndKey(Word.WdUnits.wdStory)
                        oWord.Selection.TypeParagraph()
0
Comment
Question by:Basicfarmer
  • 3
  • 3
6 Comments
 
LVL 40
ID: 40565822
Hard to tell, because a lot of information is mission to give a clear answer. What is under the Selection before you write that code? Is the cursor in a cell in the table or outside the table? Are the 2 tables already in the page or are you inserting a new table. If inserting, are you creating it from scratch or do you copy it from somewhere? Do the 2 tables have the same structure?

You should show more of the code, before and after these 2 lines.

In the meanwhile, you might try to replace TypeParagraph() by TypeText Chr(11). This is simply a change of line instead of a paragraph, so it might do the trick, depending on how you are set in the document.
0
 

Author Comment

by:Basicfarmer
ID: 40565830
Thanks for the reply. Here is the code I am using to create the table. The only way I could figure out how to get out of the table was with what I showed previously. As soon as this table is created then I will build another table. I will do this several times. I want the tables not to have a blank line between them. The tables will all have the same structure.
                        '<Build totals table>
                        Dim totalsTable As Word.Table = odoc.Tables.Add(oWord.Selection.Range, 3, 4)
                        With totalsTable
                            .Range.Font.Name = "Calibri"
                            .Range.Font.Size = 9
                            .Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
                            .Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
                            .Rows(1).Shading.BackgroundPatternColor = CType(RGB(110, 110, 100), Word.WdColor)
                            .Rows(1).Range.Font.ColorIndex = Word.WdColorIndex.wdWhite
                            .Rows(1).Range.Font.Bold = 1
                            .Rows(2).Shading.BackgroundPatternColor = CType(RGB(134, 39, 61), Word.WdColor)
                            .Rows(2).Range.Font.ColorIndex = Word.WdColorIndex.wdWhite
                            .Rows(2).Range.Font.Bold = 1
                            .Cell(1, 1).Merge(.Cell(1, 4))
                            .Cell(1, 1).Range.Text = "PROPOSED TOTALS"
                            .Cell(2, 1).Range.Text = "SYSTEM VALUE"
                            .Cell(2, 2).Range.Text = "VALUED CUSTOMER DISCOUNT"
                            .Cell(2, 3).Range.Text = "SAVINGS"
                            .Cell(2, 4).Range.Text = "SYSTEM PRICE"
                            .Cell(3, 1).Range.Text = CDec(projectList(projectRow)).ToString("C2")
                            .Cell(3, 2).Range.Text = CDec(projectDiscount(projectRow)).ToString("P2")
                            .Cell(3, 3).Range.Text = CDec(projectDiscountAmount(projectRow)).ToString("C2")
                            .Cell(3, 4).Range.Text = CDec(projectSell(projectRow)).ToString("C2")
                        End With
                        '</Build totals table>

Open in new window

0
 
LVL 40
ID: 40565852
If the tables have the same structure and you do not want them to be separated, why don't you simply go on in the same table?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Basicfarmer
ID: 40565867
The tables are grouped products. The user has the option to subtotal each group. If the groups are not subtotaled this is when i want to put the tables together. If the groups are subtotaled then i will leave the space between the tables. I can use the same loop for both conditions if I can eliminate the space between tables.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40566613
If you add a new table when the cursor is at the end of the first one, but not in its last cell, the 2 tables gets merged.

The possible problem is to work inside of the second section, because the index of the rows in there is dependent on the number of rows in the first one. You thus need a variable that will tell enable you to offset the index.

Assuming that you were at the end of the document when you ran your code:

'<YOUR PREVIOUS CODE>

Dim lastRow As Integer            'Our offset
lastRow = totalsTable.Rows.Count  'Last row of the previous table
Selection.EndKey Unit:=wdStory    'Move to the end of the previous table
totalsTable = odoc.Tables.Add(oWord.Selection.Range, 3, 4)  'Merge the 2 tables

With totalsTable
    .Range.Font.Name = "Calibri"
    .Range.Font.Size = 9
    .Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
    .Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
    .Rows(lastRow + 1).Shading.BackgroundPatternColor = CType(RGB(110, 110, 100), Word.WdColor)
    .Rows(lastRow + 1).Range.Font.ColorIndex = Word.WdColorIndex.wdWhite
    .Rows(lastRow + 1).Range.Font.Bold = 1
    .Rows(lastRow + 2).Shading.BackgroundPatternColor = CType(RGB(134, 39, 61), Word.WdColor)
    .Rows(lastRow + 2).Range.Font.ColorIndex = Word.WdColorIndex.wdWhite
    .Rows(lastRow + 2).Range.Font.Bold = 1
    .Cell(lastRow + 1, 1).Merge (.Cell(lastRow + 1, 4))
    .Cell(lastRow + 1, 1).Range.Text = "PROPOSED TOTALS"
    .Cell(lastRow + 2, 1).Range.Text = "SYSTEM VALUE"
    .Cell(lastRow + 2, 2).Range.Text = "VALUED CUSTOMER DISCOUNT"
    .Cell(lastRow + 2, 3).Range.Text = "SAVINGS"
    .Cell(lastRow + 2, 4).Range.Text = "SYSTEM PRICE"
    .Cell(lastRow + 3, 1).Range.Text = CDec(projectList(projectRow)).ToString("C2")
    .Cell(lastRow + 3, 2).Range.Text = CDec(projectDiscount(projectRow)).ToString("P2")
    .Cell(lastRow + 3, 3).Range.Text = CDec(projectDiscountAmount(projectRow)).ToString("C2")
    .Cell(lastRow + 3, 4).Range.Text = CDec(projectSell(projectRow)).ToString("C2")
End With

lastRow = totalsTable.Rows.Count 'Prepare for the following merge
'Repeat as needed

'or

lastRow = 0 'Reset if you need to restart with a separate table

Open in new window

0
 

Author Closing Comment

by:Basicfarmer
ID: 40570767
Thank you, that was exactly what I needed...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to go to Web page 2 52
System32Int Error 8 44
Spacing between controls 4 17
Redacting a row in Excel based on a term. 17 36
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

746 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

9 Experts available now in Live!

Get 1:1 Help Now