Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating tables in word 1

Status
Not open for further replies.

cp33c

Programmer
Sep 19, 2003
13
GB
Hi,

Probably an easy one. I'm trying to enter some text into a cell in a table which is in the 2nd page header. This is the code I'm using, but I keep getting a error message 'There is no table at this location', when there clearly is.

ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages).Range.Cells(1).Select
Selection.MoveRight Unit:=wdCell
Selection.Text = "This is My Name"

 
Hi cp33c,

Instead of ..
[tt] ... .Range.Cells(1).Select[/tt]
Try
[tt] ... .Range.[/tt][red][tt]Tables(1).[/tt][/red][tt]Cells(1).Select[/tt]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,

Thanks for the quick response, but unfortunately that doesn't work either. I got an error message 'Method or data member not found'. I forgot to mention I'm using Word XP.

Carl
 
Hi cp33c,

Sorry, not paying enough attention :)

Tables don't have a Cells property. You need to specify Cell(Row, Column}

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,

Thanks again for the quick response. I tried this:
ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages).Range.Tables(1).Cell(1, 1).Select

Got an error message:
'The requested member of the collection does not exist'.

Then I tried to select the whole table with this:
ActiveDocument.Sections(1).Headers(wdHeaderFooterEvenPages).Range.Tables(1).Select

Same error message. Maybe I have a problem with my table instead of the actual code.

Carl
 
Hi Carl,

You are using several collections - The Sections in the Document, the Headers in the Section, the Tables in the Header,

My instinct says that the Header is probably the one that isn't found. Do you have an even-page header in the first section of your document?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,

I've just run a message box to tell me how many sections I have in the activedocument and it said '1', so I can only assume the answer to your question is yes.

How else can I find out?

Carl
 
Hi Carl,

How many Headers do you have in Section 1?
And which of them have Tables in?

In Word, View Headers and Footers. Locate the one you are interested in and see how it is described on screen. Does it say Even Page Header?



Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,

It only says 'Header'. On the first page it says 'First Page Header'. How can I change that to say 'Even Page Header'?

Thanks
 
Hi Carl,

If it just says Header then you do not have separate Odd and Even Page Headers.

Do you want an Even Page Header? I mean, do you want one because you want to have different headers on odd and even pages? If so, then go to Page Setup (either from File on the Menu or from the Header and Footer Toolbar) and check the box on the Layout tab. Then set up your headers as you require them - then, with luck, the code should work.

If you don't actually want different headers then change your code to look at ..
[blue][tt] .... .Headers(wdHeaderFooter[/tt][red][tt]Primary[/tt][/red][tt]).Range ....[/tt][/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony,

I've worked it out thanks to you. There's a checkbox for viewing Even Headers differently to the first page and it now works.

Thanks a lot for you help

Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top