Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2020, 05:04 AM
alex100 alex100 is offline Can't apply shading to multiple sentences Windows 7 64bit Can't apply shading to multiple sentences Office 2016
Advanced Beginner
Can't apply shading to multiple sentences
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Can't apply shading to multiple sentences

In a Word document, I have two sentences separated by a carriage return. Basically, they are on two different lines.

In the second sentence, I have one word that has a red shading.

For some reason I don't know, if I select both these sentences and then apply a blue shading (via 'Shading.BackgroundPatternColor'), then this blue shading is not applied to the red shaded word too.

If however, I delete the carriage return and combine the two sentences into one sentence, then the blue shading is indeed applied to the red shaded word as well, making all the text blue.



Basically, I need to use the 'Shading.BackgroundPatternColor' property to change the color of an entire paragraph which has been priorly selected. This paragraph consists of multiple sentences, and the change must be applied to all words, including those that have been shaded before.

Removing the shading before applying the new one did not help at all. Removing the formatting of these two sentences does work, but I need to preserve that, so that's not helpful either.

So, how can I apply the 'Shading.BackgroundPatternColor' property to multiple sentences, please?

Alex
Reply With Quote
  #2  
Old 06-09-2020, 04:51 PM
macropod's Avatar
macropod macropod is offline Can't apply shading to multiple sentences Windows 7 64bit Can't apply shading to multiple sentences Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I don't see that behaviour. Regardless of the number of paragraphs involved, whatever sub-string was originally shaded red remains shaded red when blue shading is applied to the whole; it necessary to re-shade the sub-string in its own right.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-10-2020, 03:04 AM
alex100 alex100 is offline Can't apply shading to multiple sentences Windows 7 64bit Can't apply shading to multiple sentences Office 2016
Advanced Beginner
Can't apply shading to multiple sentences
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Quote:
whatever sub-string was originally shaded red remains shaded red when blue shading is applied to the whole;
Yes, this is exactly what I was describing in my message!

So my question is this... what's the best way to apply a new shading color to the whole selection?

I was thinking of something like this:

1) select all the paragraphs you need to shade;
2) apply the new shading to the whole;
3) loop through each word inside the selection;
4) check which word has a different shading than the one you just applied at step 2, and then reapply the shading to that specific word.

What do you think? Is there a faster, more elegant way to do it?

Alex
Reply With Quote
  #4  
Old 06-10-2020, 05:12 AM
macropod's Avatar
macropod macropod is offline Can't apply shading to multiple sentences Windows 7 64bit Can't apply shading to multiple sentences Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Unless there's other direct formatting you want to preserve, the simplest way is to do a font reset before applying the new shading.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-10-2020, 06:32 AM
gmaxey gmaxey is offline Can't apply shading to multiple sentences Windows 10 Can't apply shading to multiple sentences Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

How about:
Code:
Sub B()
  Selection.Font.Shading.BackgroundPatternColor = wdColorAutomatic
  Selection.Shading.BackgroundPatternColor = wdColorAqua
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 06-10-2020, 09:31 AM
alex100 alex100 is offline Can't apply shading to multiple sentences Windows 7 64bit Can't apply shading to multiple sentences Office 2016
Advanced Beginner
Can't apply shading to multiple sentences
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Greg's code works very nice.

Thank you both for your help!

Alex
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't apply shading to multiple sentences Replace or apply new header in multiple files Carchee Word VBA 41 01-26-2024 07:27 AM
Can't apply shading to multiple sentences Macro to select multiple sentences that contain a specific word MauiTruss Word VBA 7 10-03-2018 03:46 PM
Can't apply shading to multiple sentences how to apply a calendar to multiple activities ketanco Project 1 10-15-2014 06:56 AM
Can't apply shading to multiple sentences How to apply formatting(color & shading) to specific letters in whole doc. (arabic) loopseye Word 3 08-05-2013 10:49 PM
Can't apply shading to multiple sentences Apply template to multiple documents Oliver Beirne Word VBA 2 04-24-2012 04:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:57 PM.


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