Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 02-13-2023, 03:08 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: 73
Ddadoo57 is on a distinguished road
Default



Quote:
Originally Posted by Ddadoo57 View Post
Thank you Gmayor,

I will adapt the code to my needs and send you back what I have modified and/or added. Maybe it will help someone a little bit too.

If not, I only had hidden fields in the headers, not in the footers. It's amazing that it takes that into account.

Best regards,
Hello,

The problem I have now is that when updating the fields, for each footer, the screen display changes, it goes from normal mode to draft mode or something like that, and it's not great for the user.

I partly solve this problem with :
Application.Visible = False
...
Application.Visible = True
ActiveWindow.View.Type = wdNormalView
ActiveWindow.View.Type = wdPrintView

Well, it's not great, since the application disappears and comes back once the job is done.
Is there any solution to keep the screen from moving or changing, like "oFooter.Range.Delete" does so nicely?

Best regards,
David
Reply With Quote
  #17  
Old 02-13-2023, 03:56 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,106
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 of
Default

It sounds like you are selecting something in the header/footer ranges rather than using the ranges to make changes. If you use the code I posted there is no selection involved and the screen display should not change . The update merely shows the field result.
__________________
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
  #18  
Old 02-13-2023, 07:49 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: 73
Ddadoo57 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
It sounds like you are selecting something in the header/footer ranges rather than using the ranges to make changes. If you use the code I posted there is no selection involved and the screen display should not change . The update merely shows the field result.
Hi and thanks for your feedback!

I'll check if it could be from another procedure or function done before. In this one, I only use Range and not Seclection.

See you later
Reply With Quote
  #19  
Old 02-13-2023, 12:25 PM
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: 73
Ddadoo57 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
It sounds like you are selecting something in the header/footer ranges rather than using the ranges to make changes. If you use the code I posted there is no selection involved and the screen display should not change . The update merely shows the field result.


I inserted the following lines, at the beginning and end of the procedure, solves the problem for 98% ;-)

Application.ScreenUpdating = False
ActiveDocument.ActiveWindow.View.SeekView = wdSeekCurrentPageFooter
...
ActiveWindow.View.Type = wdNormalView
ActiveWindow.View.Type = wdPrintView

It works, but from time to time I have a small right and left of the document (not of the window nor of the tab) at the insertion of the footers. I insert or delete the footers through a checkbox.

In the procedure AutoNew() and OnLoad(ribbon As IRibbonUI), I don't have any Selection, I only have Ranges. I don't seem to have any other procedure or function called when creating or opening the document.

Sincerely,
David
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 09:45 AM.


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