J
Jimmy
Hi,
I need to add a footer that looks like the following in a document
that's generated using VBA:
Page X of Y
Creation date: yyyy-mm-dd
Can anyone tell me why I can't get it with this bit of code?
With Doc.Sec(1).Footers(wdHeaderFooterPrimary)
Set rngFooter = .Range
With rngFooter
.Text = "Page "
.Collapse wdCollapseEnd
.Fields.Add Range:=rngFooter, Type:=wdFieldPage
.Collapse wdCollapseEnd
'Here I have : Page X
.Text = "of "
'At this point : Page of X
.Collapse wdCollapseEnd
.Fields.Add Range:=rngFooter, Type:=wdFieldNumPages
'Page of YX
.Collapse wdCollapseEnd
.Text = "Created on : "
'Page of Created on : YX
.Collapse wdCollapseEnd
.InsertDateTime "yyyy-mm-dd", insertasfield:=False
'Page of Created on : yyyy-mm-ddYX
End With
End With
It looks like the collapse method doesn't consider any of the fields
as part of the range. Does anyone have a solution? I would prefer not
to use Selection since my document window is not visible and I wish to
keep it that way.
TIA
Jimmy
I need to add a footer that looks like the following in a document
that's generated using VBA:
Page X of Y
Creation date: yyyy-mm-dd
Can anyone tell me why I can't get it with this bit of code?
With Doc.Sec(1).Footers(wdHeaderFooterPrimary)
Set rngFooter = .Range
With rngFooter
.Text = "Page "
.Collapse wdCollapseEnd
.Fields.Add Range:=rngFooter, Type:=wdFieldPage
.Collapse wdCollapseEnd
'Here I have : Page X
.Text = "of "
'At this point : Page of X
.Collapse wdCollapseEnd
.Fields.Add Range:=rngFooter, Type:=wdFieldNumPages
'Page of YX
.Collapse wdCollapseEnd
.Text = "Created on : "
'Page of Created on : YX
.Collapse wdCollapseEnd
.InsertDateTime "yyyy-mm-dd", insertasfield:=False
'Page of Created on : yyyy-mm-ddYX
End With
End With
It looks like the collapse method doesn't consider any of the fields
as part of the range. Does anyone have a solution? I would prefer not
to use Selection since my document window is not visible and I wish to
keep it that way.
TIA
Jimmy