H
Huw
Hello,
I am trying to write code to programatically create a table in a word footer
and insert fields into this table. When recording the macro that word creates
it show's up as using the selection object but I want to use the range object
(which should have all the functionality and more of the selection object).
However when running the code it comes up with error 4605 - "The command is
not available."
Here is the snippet of code -
Sub test()
Dim oFooter As HeaderFooter
Dim oSection As Section
Dim oRange As Range
Dim oTable As Table
Dim oCell As Cell
' Add the table and data to the footer
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
Set oRange = oFooter.Range
Set oTable = oRange.Tables.Add(oRange, 1, 3)
Set oCell = oTable.Cell(1, 1)
Set oRange = oCell.Range
oRange.Fields.Add oRange, wdFieldPage
Next oFooter
Next oSection
End Sub
Has anyone got a workaround or a reason why this happens. It happens on all
platforms of word (tried it on word 2002 SP3 and word 97 SR 2)
Thanks,
Huw
I am trying to write code to programatically create a table in a word footer
and insert fields into this table. When recording the macro that word creates
it show's up as using the selection object but I want to use the range object
(which should have all the functionality and more of the selection object).
However when running the code it comes up with error 4605 - "The command is
not available."
Here is the snippet of code -
Sub test()
Dim oFooter As HeaderFooter
Dim oSection As Section
Dim oRange As Range
Dim oTable As Table
Dim oCell As Cell
' Add the table and data to the footer
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
Set oRange = oFooter.Range
Set oTable = oRange.Tables.Add(oRange, 1, 3)
Set oCell = oTable.Cell(1, 1)
Set oRange = oCell.Range
oRange.Fields.Add oRange, wdFieldPage
Next oFooter
Next oSection
End Sub
Has anyone got a workaround or a reason why this happens. It happens on all
platforms of word (tried it on word 2002 SP3 and word 97 SR 2)
Thanks,
Huw