#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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] |
#3
|
|||
|
|||
Quote:
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 |
#4
|
||||
|
||||
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] |
#5
|
|||
|
|||
How about:
Code:
Sub B() Selection.Font.Shading.BackgroundPatternColor = wdColorAutomatic Selection.Shading.BackgroundPatternColor = wdColorAqua End Sub |
#6
|
|||
|
|||
Greg's code works very nice.
Thank you both for your help! Alex |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Replace or apply new header in multiple files | Carchee | Word VBA | 41 | 01-26-2024 07:27 AM |
Macro to select multiple sentences that contain a specific word | MauiTruss | Word VBA | 7 | 10-03-2018 03:46 PM |
how to apply a calendar to multiple activities | ketanco | Project | 1 | 10-15-2014 06:56 AM |
How to apply formatting(color & shading) to specific letters in whole doc. (arabic) | loopseye | Word | 3 | 08-05-2013 10:49 PM |
Apply template to multiple documents | Oliver Beirne | Word VBA | 2 | 04-24-2012 04:49 AM |