Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-29-2019, 03:24 PM
dita dita is offline Adding exceptions to macro Windows XP Adding exceptions to macro Office 2010 64bit
Advanced Beginner
Adding exceptions to macro
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default Adding exceptions to macro


Is there any way to add exceptions to a macro? For example, I´m using a macro that affects to all content in a document but dont want to apply it to certain elements such as hyperlinks or graphics. If this is possible, what´s the code to insert for that?
Reply With Quote
  #2  
Old 10-29-2019, 06:01 PM
Guessed's Avatar
Guessed Guessed is offline Adding exceptions to macro Windows 10 Adding exceptions to macro Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
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

There is lots of ways to add exceptions but you haven't provided enough information on what your code is actually doing.

Post your code and describe the problem clearly so someone can help you.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-04-2019, 02:42 AM
dita dita is offline Adding exceptions to macro Windows XP Adding exceptions to macro Office 2010 64bit
Advanced Beginner
Adding exceptions to macro
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default

Sorry, this the macro where I want to insert the exception.


I want to change font color to red. The exception are the hyperlinks. Any URL in the document should keep their color without changing to red.


Sub Macro1()
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = wdColorRed
Selection.Find.Execute Replace:=wdReplaceAll
End Sub


Thanks!
Reply With Quote
  #4  
Old 11-04-2019, 04:53 AM
gmayor's Avatar
gmayor gmayor is offline Adding exceptions to macro Windows 10 Adding exceptions to macro Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

Code:
If Not Selection.Range.Hyperlinks.Count > 0 Then
        Selection.Find.Replacement.Font.Color = wdColorRed
End If
__________________
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
  #5  
Old 11-04-2019, 09:53 AM
dita dita is offline Adding exceptions to macro Windows XP Adding exceptions to macro Office 2010 64bit
Advanced Beginner
Adding exceptions to macro
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default

It works. Thanks a million!


What if the exception is for all tables in a document?
I mean, preserving the color formatting in all content within a table. What´s the exception code for that?
Reply With Quote
  #6  
Old 11-05-2019, 02:36 AM
Guessed's Avatar
Guessed Guessed is offline Adding exceptions to macro Windows 10 Adding exceptions to macro Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,966
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

Dita

If you want to learn to code for exceptions you need to study code already on this forum to see how people have dealt with issues. For instance, a good example of dealing with table content and exceptions can be seen in this thread https://www.msofficeforums.com/word-...ll-tables.html

The code Graham provided is very simplistic and provides a 'test' but doesn't selectively apply formatting to the non-hyperlink parts of the selection. It is an 'all or nothing' approach which looks to see if there are ANY hyperlinks in the selection and if not, formats the whole selection. To apply the colour to chunks of the selection which aren't hyperlinks requires a lot more code and could be approached in few different ways. Probably the easiest would be to format everything selected as red and then loop through any hyperlinks and turn them back to your preferred colour.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 11-08-2019, 07:27 AM
dita dita is offline Adding exceptions to macro Windows XP Adding exceptions to macro Office 2010 64bit
Advanced Beginner
Adding exceptions to macro
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default

Very interesting link to learn about the exceptions. Thanks you both for your help!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding exceptions to macro Adding another macro in the macro list Marcia Excel Programming 6 11-07-2018 04:13 AM
Adding exceptions to macro Making exceptions to PROPER Chayes Excel Programming 8 06-05-2018 07:19 AM
Exceptions on my documents Martinod Word 1 03-12-2018 11:53 AM
Adding exceptions to macro Adding to a macro Ulodesk Word VBA 4 03-07-2016 01:40 PM
Autocorrect Exceptions not working danvdr Word 6 05-26-2014 09:37 PM

Other Forums: Access Forums

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