Update a cell in tables in header in word document using .net


I have opened a word document in vb.net. This word document has table in header and in the document. I tried updating a table in document it works fine. But not able to succeed in updating table which is in header. Need help to know the syntax to update the table in header.

'update table
Dim r As Integer, c As Integer
oTable = oDoc.Tables(1)
oTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 1 To 1
For c = 1 To 4
oTable.Cell(r, c).Range.Text = "r" & r & "c" & c

'update table in header
Dim footerRange As Word.Range = oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Tables(1)
footerRange.Cells(1).Range.Text = "RR"

"The requested member of the collection does not exist."

Dim footerRange As Word.Range = oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range‌​.Tables(1)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try EDITED

Dim headerRange As Word.Range = oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
headerRange.Tables(1).Cell(1, 1).Range.Text = "RR"

sivaperiAuthor Commented:
This didn't work, got a error message "The requested member of the collection does not exist." at line
headerRange.Tables(1).Cell(1, 1).Range.Text = "RR"

Open in new window

Are you trying to edit the footer or the header

Dim footerRange As Word.Range = oDoc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
 footerRange.Tables(1).Cell(1, 1).Range.Text = "RR"

Could you send a dummy word file?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sivaperiAuthor Commented:
It worked fine with your code...but have to change one thing "wdheaderFooterFirstPage" to WdHeaderFooterIndex.wdHeaderFooterPrimary
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.