Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-09-2023, 07:29 AM
Ddadoo57 Ddadoo57 is offline ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Windows 11 ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Office 2021
Advanced Beginner
...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=...
 
Join Date: Feb 2023
Posts: 94
Ddadoo57 is on a distinguished road
Default


Quote:
Originally Posted by gmayor View Post
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


thanks i will try that too!

Cordially
Reply With Quote
  #2  
Old 02-09-2023, 07:47 AM
Ddadoo57 Ddadoo57 is offline ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Windows 11 ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Office 2021
Advanced Beginner
...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=...
 
Join Date: Feb 2023
Posts: 94
Ddadoo57 is on a distinguished road
Default

Quote:
Originally Posted by Ddadoo57 View Post
thanks i will try that too!

Cordially
I just gave it a try and it seems to work great!

I will adapt it to my code to insert it in the footer

Thank you so much !
Reply With Quote
  #3  
Old 02-09-2023, 09:31 AM
Ddadoo57 Ddadoo57 is offline ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Windows 11 ...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=... Office 2021
Advanced Beginner
...Fields.Add Range:=Selection.Range, Type:=wdFieldIf, Text:=...
 
Join Date: Feb 2023
Posts: 94
Ddadoo57 is on a distinguished road
Default

Thank you very much Gmayor !
Reply With Quote
Reply



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 08:54 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