View Single Post
 
Old 02-09-2023, 05:58 AM
Ddadoo57 Ddadoo57 is offline Windows 11 Office 2021
Advanced Beginner
 
Join Date: Feb 2023
Posts: 90
Ddadoo57 is on a distinguished road
Default ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=...

Good morning,

I would like to insert a wdFieldIf or wdFieldExpression type field but I'm having a problem.

When I write the text of the field (see below), the starting and ending brace are created and interpreted automatically and correctly by VBA, but the ones inside (around PAGE and NUMPAGES) are not , they are created as standard characters and are not interpreted.

Here is my VBA code:

ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:="{PAGE} = {NUMPAGES} ""last page""", PreserveFormatting:=True

How to do "Ctrl+F9" in VBA code to generate interpretable braces for PAGE and NUMPAGES?

Cordially,
David
Reply With Quote