M
Michael Gordon
I'm trying to insert a page number field inside a table inside a header.
Basically, I want the text in Cell 1,1 to print, then Cell 1,2 should have
"Page X" in it. Here's what I have so far:
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
'Wipe out header
..Select
Selection.Delete
'Add table
..Tables.Add
Range:=ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range,
NumRows:=1, NumColumns:=2
..Tables(1).Cell(1, 1).Select
Selection.TypeText Text:="Text goes here"
..Tables(1).Cell(1, 2).Select
'Selection.TypeText Text:=
Dim rng As Range
Set rng = .Tables(1).Cell(1, 2).Range
rng.ParagraphFormat.Alignment = wdAlignParagraphRight
rng.Text = "Page "
rng.Collapse wdCollapseEnd
rng.Fields.Add rng, wdFieldPage
Unfortunately, at that last line, I get Run-Time Error 4605: "This command
is not available."
I've narrowed it down to the fact that it's in a table. How can I fix this?
I'm working on Word 2007 12.0.6311.5000.
Thanks!
Basically, I want the text in Cell 1,1 to print, then Cell 1,2 should have
"Page X" in it. Here's what I have so far:
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
'Wipe out header
..Select
Selection.Delete
'Add table
..Tables.Add
Range:=ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range,
NumRows:=1, NumColumns:=2
..Tables(1).Cell(1, 1).Select
Selection.TypeText Text:="Text goes here"
..Tables(1).Cell(1, 2).Select
'Selection.TypeText Text:=
Dim rng As Range
Set rng = .Tables(1).Cell(1, 2).Range
rng.ParagraphFormat.Alignment = wdAlignParagraphRight
rng.Text = "Page "
rng.Collapse wdCollapseEnd
rng.Fields.Add rng, wdFieldPage
Unfortunately, at that last line, I get Run-Time Error 4605: "This command
is not available."
I've narrowed it down to the fact that it's in a table. How can I fix this?
I'm working on Word 2007 12.0.6311.5000.
Thanks!