insert pagenumber in table in footer

  • Thread starter Örjan Skoglösa
  • Start date
Ö

Örjan Skoglösa

Hi,

I have a document with a lot of sections and different footers.

In every footer is a table.

I want to insert a pagenumber field in a certain cell of the table.

When I run my code I get the error message that the object does not
support this method.

TIA
Örjan

----------

Sub test()
Dim mySec, myFooter, myField
For Each mySec In ActiveDocument.Sections
For Each myFooter In mySec.Footers
Set myField =
myFooter.Fields.Add(Range:=myFooter.Range.Tables(1).Cell(Row:=1,
Column:=1).Range, _
Type:=wdFieldPage)
Next
Next
End Sub
 
Ö

Örjan Skoglösa

Never mind.

I found out I have to select the cell and then collapse the selection
before inserting the field.

Sub test()
Dim mySec, myFooter, myField
For Each mySec In ActiveDocument.Sections
For Each myFooter In mySec.Footers
myFooter.Range.Tables(1).Cell(Row:=1, Column:=1).Range.Select
With Selection
.Collapse Direction:=wdCollapseStart
.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
End With
Next
Next
End Sub

BR,
Örjan
 

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