Why does this code runs in one case and fails in another?

  • Thread starter Aristotelis E. Charalampakis
  • Start date
A

Aristotelis E. Charalampakis

I am new to VBA.

I am using the following code within VB 6.0 to print "Page XXX of YYY
- Copyright ...." in the footer of two documents.

Dim rngFooter As Object 'if i define it as Range, nothing
happens
Set rngFooter =
myWord.ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
rngFooter.Text = "Page "
rngFooter.Collapse wdCollapseEnd
rngFooter.Move wdCharacter, 1
rngFooter.Fields.Add rngFooter, wdFieldPage
rngFooter.Collapse wdCollapseEnd
rngFooter.Move wdCharacter, 1
rngFooter.Text = " of "
rngFooter.Collapse wdCollapseEnd
rngFooter.Move wdCharacter, 1
rngFooter.Fields.Add rngFooter, wdFieldNumPages
rngFooter.Collapse wdCollapseEnd
rngFooter.Move wdCharacter, 1
rngFooter.Text = " - Copyright ...."

Strangely, this works as expected in one case and fails in the other.
In the failed case, the footer becomes "Page XXXYYY" with no space in
between. If the document has 23 pages, the footers become "Page 123",
"Page 223", etc.

Any ideas?
TIA
Aristotelis
 

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