Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2023, 12:28 PM
ctviggen ctviggen is offline In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve? Windows 10 In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve? Office 2016
Advanced Beginner
In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve?
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve?

I have a macro I've been using that cleans up documents. For instance, for the sentence "This is like X i.e. which is like Y", my macro adds commas before and after "i.e.": "This is like X, i.e., which is like Y".



This macro has the following code at the beginning:

Code:
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
I have determined what "ClearFormatting" does, but why do I have two statements in a row like this, and what does "Replacement" add?

(The macro works fine, but I added something before these lines, and went to comment these lines...only to realize I'm not sure what they do.)
Reply With Quote
  #2  
Old 11-29-2023, 05:37 PM
Guessed's Avatar
Guessed Guessed is offline In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve? Windows 10 In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Those two lines remove any possible remnants of formatting from the Find and Replace dialog before you set the new search parameters. This is necessary sometimes if a previous find and replace was performed and you had set a particular format to go along with either the find string or the replace with. For example, if you did a search for the word Title and only wanted to find the instances that were bold and then you wanted to assign it as a Heading 1 style then the bold would be a find format and the style setting would be a find.replacement format.

Those settings are sticky - which means the settings are remembered if you close the dialog and then later re-open it without restarting Word.

Those lines of code remove those format settings to the find/replace doesn't retain anything you forgot about.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 12-04-2023, 10:06 AM
ctviggen ctviggen is offline In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve? Windows 10 In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve? Office 2016
Advanced Beginner
In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve?
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default

Thank you very much. That is a great explanation and I have commented my file accordingly.



I will keep this in mind for my other programs too.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003: VBA "Function" causes "#VALUE!" errors after running "insert/delete row" custom macro Matt C Excel Programming 2 01-08-2022 06:03 AM
In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve? Creating a "super macro" with all kind of functions Xanthopteryx PowerPoint 1 06-16-2016 01:38 AM
How to send "clean" copy after tracking/ redlining changes in review mode lindapaul Word 2 06-09-2016 02:34 PM
remove repeated words with " macro " or " wild cards " in texts with parentheses and commas jocke321 Word VBA 2 12-10-2014 11:27 AM
In a macro to clean up language, what functions do "ClearFormatting" and "Replacement" serve? How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:31 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