Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 02-09-2023, 07:15 AM
gmayor's Avatar
gmayor gmayor is offline ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Windows 10 ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You should change the range then add fields e.g.
Code:
Dim oRng As Range
Set oRng = Selection.Range
With oRng
    .Fields.Add Range:=oRng, Type:=wdFieldIf, Text:="{PAGE} = {NUMPAGES} ""last page""", PreserveFormatting:=False
    .Collapse 1
    .MoveEndUntil "}"
    .End = .End + 1
    .MoveStartUntil "{"
    .Text = ""
    .Fields.Add Range:=oRng, Type:=wdFieldPage, PreserveFormatting:=False
    .Collapse 0
    .MoveEndUntil "}"
    .End = .End + 1
    .MoveStartUntil "{"
    .Text = ""
    .Fields.Add Range:=oRng, Type:=wdFieldNumPages, PreserveFormatting:=False
    .Fields.Update
End With
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Distribute text in one cell across a range of cells (overcoming selection.range.cells.count bug) slaycock Word VBA 0 02-18-2017 07:00 AM
...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Working with Selection.range. PRA007 Word VBA 2 02-19-2016 12:52 AM
...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Search and reduce the range of a text selection paik1002 Word VBA 1 12-17-2015 04:51 AM
Selection or Range Tommes93 Word VBA 1 04-10-2014 02:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft