Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-03
5
Medium Priority
?
939 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
  • 2
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

927 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