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.ParagraphForm at.SpaceAf ter = 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(W ord.WdHead erFooterIn dex.wdHead erFooterFi rstPage).R ange.Table s(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(W ord.WdHead erFooterIn dex.wdHead erFooterFi rstPage).R ange.Tab les(1)
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.ParagraphForm
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(W
footerRange.Cells(1).Range
Error:
"The requested member of the collection does not exist."
in:
Dim footerRange As Word.Range = oDoc.Sections(1).Headers(W
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"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
pls try EDITED
Dim headerRange As Word.Range = oDoc.Sections(1).Headers(W
headerRange.Tables(1).Cell
Regards