Solved

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

Posted on 2014-09-03
5
818 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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:

752 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