Solved

How do I add a table header to a Word document header using VB.net?

Posted on 2014-09-03
5
858 Views
Last Modified: 2016-11-24
I need to add the header of my Word table to the header of page 2 and above in a Word document.  I have it appearing on the first page but none there after.  I think I know where the problem is but I don't know how to fix it.  Any help is most welcomed!!

Here is the code.  I think the bolded area is where I need to put something but what?  

With oDoc
                oSec = .Sections(1)
                oSec.PageSetup.DifferentFirstPageHeaderFooter = True
                oSec.Range.InsertAfter("Appendix E: White Sands Test Facility Reporting Period:  " & trainee & vbCrLf & "Summary of Maximum Concentrations, Current Concentrations and T-C Plot Interpretations for WSTF Monitoring Well Network")

               oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 1, 19)
               oTable.Range.ParagraphFormat.SpaceBefore = 3
                oTable.Range.ParagraphFormat.SpaceAfter = 3
                oTable.Borders.Enable = True
                oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
                oTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
                oTable.Range.Font.Bold = False
                oTable.Range.Font.Size = 8
                oTable.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
                oTable.Range.Font.Color = Word.WdColor.wdColorBlack
                oTable.Range.Font.Italic = False
               
                'column headings
                oTable.Cell(1, 1).Range.Text = CStr("Well")
                oTable.Cell(1, 2).Range.Text = CStr("First" & vbCrLf & "Sample")
                oTable.Cell(1, 3).Range.Text = CStr("Interpretation")

                oTable.Cell(1, 4).Range.Text = CStr("F11" & vbCrLf & "Max")
                oTable.Cell(1, 5).Range.Text = CStr("F11" & vbCrLf & "Year")
                oTable.Cell(1, 6).Range.Text = CStr("F11" & vbCrLf & "Last")
                oTable.Cell(1, 7).Range.Text = CStr("F11" & vbCrLf & "Year")

                oTable.Cell(1, 8).Range.Text = CStr("F113" & vbCrLf & "Max")
                oTable.Cell(1, 9).Range.Text = CStr("F113" & vbCrLf & "Year")
                oTable.Cell(1, 10).Range.Text = CStr("F113" & vbCrLf & "Last")
                oTable.Cell(1, 11).Range.Text = CStr("F113" & vbCrLf & "Year")

                oTable.Cell(1, 12).Range.Text = CStr("TCE" & vbCrLf & "Max")
                oTable.Cell(1, 13).Range.Text = CStr("TCE" & vbCrLf & "Year")
                oTable.Cell(1, 14).Range.Text = CStr("TCE" & vbCrLf & "Last")
                oTable.Cell(1, 15).Range.Text = CStr("TCE" & vbCrLf & "Year")

                oTable.Cell(1, 16).Range.Text = CStr("NDMA" & vbCrLf & "(607)" & vbCrLf & "Max")
                oTable.Cell(1, 17).Range.Text = CStr("NDMA" & vbCrLf & "(607)" & vbCrLf & "Year")
                oTable.Cell(1, 18).Range.Text = CStr("NDMA" & vbCrLf & "(607)" & vbCrLf & "Last")
                oTable.Cell(1, 19).Range.Text = CStr("NDMA" & vbCrLf & "(607)" & vbCrLf & "Year")

                oTable.Rows(1).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray15
                oTable.Columns.Item(1).Width = oWord.InchesToPoints(0.7) ' well
                oTable.Columns.Item(2).Width = oWord.InchesToPoints(0.75)
                oTable.Columns.Item(3).Width = oWord.InchesToPoints(0.8)

                oTable.Columns.Item(4).Width = oWord.InchesToPoints(0.6) '
                oTable.Columns.Item(5).Width = oWord.InchesToPoints(0.4)
                oTable.Columns.Item(6).Width = oWord.InchesToPoints(0.6)
                oTable.Columns.Item(7).Width = oWord.InchesToPoints(0.4)
                oTable.Columns.Item(8).Width = oWord.InchesToPoints(0.6)
                oTable.Columns.Item(9).Width = oWord.InchesToPoints(0.4)
                oTable.Columns.Item(10).Width = oWord.InchesToPoints(0.6)
                oTable.Columns.Item(11).Width = oWord.InchesToPoints(0.4)
                oTable.Columns.Item(12).Width = oWord.InchesToPoints(0.6)
                oTable.Columns.Item(13).Width = oWord.InchesToPoints(0.4)
                oTable.Columns.Item(14).Width = oWord.InchesToPoints(0.6)
                oTable.Columns.Item(15).Width = oWord.InchesToPoints(0.4)
                oTable.Columns.Item(16).Width = oWord.InchesToPoints(0.6)
                oTable.Columns.Item(17).Width = oWord.InchesToPoints(0.5)
                oTable.Columns.Item(18).Width = oWord.InchesToPoints(0.6)
                oTable.Columns.Item(19).Width = oWord.InchesToPoints(0.5)

                oSec.Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = "Appendix E:  Summary of Maximum Concentrations, Current Concentrations and T-C Plot Interpretations for WSTF Monitoring Well Network" _
                   & vbCrLf ' ===== DO I PUT SOMETHING HERE??? ====

                '=====================================================

                oSec.Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = "NASA White Sands Test Facility for Reporting Period:  " & trainee
            End With
0
Comment
Question by:Karen Wilson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40301324
I might be wrong, but I think that you are confusing the table heading with the document header.

You can set the table heading like this:
MyTable.Rows(1).HeadingFormat = true

Open in new window

You could use the document header instead, but it won't look like part of the table. And anyway, in this case you specify that the first page header is different, so it won't be repeated on the  following pages.
0
 

Author Comment

by:Karen Wilson
ID: 40301652
I am going to try your method as it makes more sense.  I was trying to duplicate how the report was given to me, which had the table header also as the document header.  Thanks!
0
 

Author Closing Comment

by:Karen Wilson
ID: 40301665
Perfect!! Thanks so much!!

For those who want to know what I did, see below:

oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, hCount + 1, 19)
                    oTable.Range.ParagraphFormat.SpaceBefore = 3
                    oTable.Range.ParagraphFormat.SpaceAfter = 3
                    oTable.Borders.Enable = True
                    oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
                    oTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
                    oTable.Range.Font.Bold = False
                    oTable.Range.Font.Size = 8
                    oTable.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
                    oTable.Range.Font.Color = Word.WdColor.wdColorBlack
                    oTable.Range.Font.Italic = False
                    oTable.Rows(1).HeadingFormat = True
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40301773
Pleased to have got you on the right track. Thank you for the feedback.
0
 

Expert Comment

by:Ritesh Hegde
ID: 41901155
Hello,

I would like to add two footers in a word document using VB.net script. How is this possible? Can any1 help me.?

Basically I need something which has a left side footer and right side footer. I think, we need to add 2 column table as footer but i am not sure how to do this.

Thanks in advance for help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

628 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