Inserting an expression field

P

Peter

I have "Page X of Y" in a header where Y is normally a field of type
wdFieldNumPages. I have modified this field manually by inserting an
expression field (i.e. type wdFieldExpression) that reads "= expression - 3"
where expression in this case is the NumPages field. This works as intended
and I can create this manually. I need to create it programmatically however
because the -3 could be -1 or -2, etc. I cannot find any documentation on how
to specifiy the expression when creating a field of this type. Also, when I
look this field I created manually from the locals window in a macro, I can
see that the NUMPAGES field is contained within the expression field.
Does anyone have any idea how I can do this programmatically?

Thanks!
 
J

Jay Freedman

Peter said:
I have "Page X of Y" in a header where Y is normally a field of type
wdFieldNumPages. I have modified this field manually by inserting an
expression field (i.e. type wdFieldExpression) that reads "=
expression - 3" where expression in this case is the NumPages field.
This works as intended and I can create this manually. I need to
create it programmatically however because the -3 could be -1 or -2,
etc. I cannot find any documentation on how to specifiy the
expression when creating a field of this type. Also, when I look this
field I created manually from the locals window in a macro, I can see
that the NUMPAGES field is contained within the expression field.
Does anyone have any idea how I can do this programmatically?

Thanks!

It isn't easy. See
http://word.mvps.org/FAQs/MacrosVBA/NestedFieldsWithVBA.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
P

Peter

Thank you very much. I have read the article and it is very informative. You
are right that this is not easy but, I found an easier way to accomplish what
I needed. Instead of hardcoding the number to subtract from NUMPAGES (and
subsequently update it in VBA, I substituted a DOCVARIABLE field. I did this
manually in the template. Now my macro simply updates the DOCVARIABLE and
updates the fields.

Thanks again!
Peter
 

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