Change text in a table in a header

S

sriddle68

I have a header that contains a table to which I want to put text into
each cell in the table.
I am having a problem writing to that table. When I run the code
snipit below I put in a table(1).select to be able to visually see
where table #1 is and where I should expect the text to show up. It
highlights my header table just fine but the next line puts "B123"
into a table in the body of the document not the header table.
How can I write specifically to the table in the header?

Thanks
Scott Riddle

Sub Macro4()
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Tables(1).Select
ActiveDocument.Tables(1).Cell(1, 1).Range.Text = "B123"
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
 
D

Doug Robbins - Word MVP on news.microsoft.com

Use

There is no need to Select the table

With
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1)
.Cell(1, 1).Range.Text = "B123"
End With

however, in your code, after selecting the table, you then used
ActiveDocument.Tables(1). If you had used Selection.Tables(1) it would have
worked.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
S

sriddle68

I dropped the with and end with and it worked great. I am so used to
Excel and how it works that Word always seems to be a struggle for me.

Thanks again
Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top