Link to home
Start Free TrialLog in
Avatar of sivaperi
sivaperi

asked on

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

Hello,

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
Next
Next

'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"

Error:
"The requested member of the collection does not exist."
in:

Dim footerRange As Word.Range = oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range‌​.Tables(1)
Avatar of Rgonzo1971
Rgonzo1971

Hi,

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"

Regards
Avatar of sivaperi

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial