J
John Henry
In using VBA I need to add a 1 row, 2 column int the footer. In the left
column I need to display the current date and in the right column display
page of pages. I can create the table, display the current date, but I
cannot seem to add the page of pages to the right column.
The error message I receive is: This command is not available.
What I am trying to do is grab the cell as a range, then use that range to
get the field result. I have used the activedocument.fields.add method, but
it displays the the results right on document and not where I need it.
Does anyone have any suggestions?
Here is my code:
Dim myRange As Range
Dim strPageFld As String, strTotPageFld As String
With ActiveDocument
Set myRange = .Sections(1).Footers(wdHeaderFooterPrimary).Range
.Tables.Add Range:=myRange, NumRows:=1, NumColumns:=2
myRange.Tables(1).Cell(1, 1).Range.ParagraphFormat.Alignment =
wdAlignParagraphLeft
myRange.Tables(1).Cell(1, 1).Range.Text = Format(Date, "MMMM dd,
yyyy")
Set myRange = myRange.Tables(1).Cell(1, 2).Range
myRange.ParagraphFormat.Alignment = wdAlignParagraphRight
strPageFld = myRange.Fields.Add(myRange, wdFieldPage).Result
strTotPageFld = myRange.Fields.Add(myRange, wdFieldNumPages).Result
myRange.Text = strPageFld & " of " & strTotPageFld
End With
column I need to display the current date and in the right column display
page of pages. I can create the table, display the current date, but I
cannot seem to add the page of pages to the right column.
The error message I receive is: This command is not available.
What I am trying to do is grab the cell as a range, then use that range to
get the field result. I have used the activedocument.fields.add method, but
it displays the the results right on document and not where I need it.
Does anyone have any suggestions?
Here is my code:
Dim myRange As Range
Dim strPageFld As String, strTotPageFld As String
With ActiveDocument
Set myRange = .Sections(1).Footers(wdHeaderFooterPrimary).Range
.Tables.Add Range:=myRange, NumRows:=1, NumColumns:=2
myRange.Tables(1).Cell(1, 1).Range.ParagraphFormat.Alignment =
wdAlignParagraphLeft
myRange.Tables(1).Cell(1, 1).Range.Text = Format(Date, "MMMM dd,
yyyy")
Set myRange = myRange.Tables(1).Cell(1, 2).Range
myRange.ParagraphFormat.Alignment = wdAlignParagraphRight
strPageFld = myRange.Fields.Add(myRange, wdFieldPage).Result
strTotPageFld = myRange.Fields.Add(myRange, wdFieldNumPages).Result
myRange.Text = strPageFld & " of " & strTotPageFld
End With