creating nested fields

L

Luc Benninger

I fail to create nested fields. I would like my vba code to insert
following formula into a table cell:

{={ NUMPAGES \* MERGEFORMAT }+3}

any hints greatly appreciated!
Luc
 
D

Dave Lett

Hi Luc,

There are many ways you could do this, and this is only one:

Selection.Fields.Add _
Range:=Selection.Range, _
Type:=wdFieldNumPages, _
Text:="", _
PreserveFormatting:=True

Set oRng = Selection.Paragraphs(1).Range
With oRng
.MoveEnd unit:=wdCharacter, Count:=-1
.InsertBefore Text:="="
.InsertAfter Text:="+3"
.Select
End With
With Selection.Fields
.Add _
Range:=Selection.Range, _
Type:=wdFieldEmpty, _
PreserveFormatting:=False
.Update
End With

HTH,
Dave
 
L

Luc Benninger

Dave, thanks a lot!

Dave said:
Hi Luc,

There are many ways you could do this, and this is only one:

Selection.Fields.Add _
Range:=Selection.Range, _
Type:=wdFieldNumPages, _
Text:="", _
PreserveFormatting:=True

Set oRng = Selection.Paragraphs(1).Range
With oRng
.MoveEnd unit:=wdCharacter, Count:=-1
.InsertBefore Text:="="
.InsertAfter Text:="+3"
.Select
End With
With Selection.Fields
.Add _
Range:=Selection.Range, _
Type:=wdFieldEmpty, _
PreserveFormatting:=False
.Update
End With

HTH,
Dave
 
C

Charles Kenyon

Another alternative is to create your field manually, save it as an AutoText
entry, and use code to insert the AutoText.
 

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