![]() |
|
#1
|
|||
|
|||
![]() Quote:
|
#2
|
|||
|
|||
![]()
Hi again! Unfortunaltely, from the very beginning it was not clear that the document had a page filling color. After the misunderstanding has been corrected, here's the code that seems to work:
Code:
Sub Deshading() Dim oPara As Paragraph 'If the selection includes tables, error 4605 will be returned. 'Thus, an error handler is needed: On Error Resume Next Application.ScreenUpdating = False For Each oPara In ActiveDocument.range.Paragraphs oPara.range.Select If Not selection.Shading.BackgroundPatternColor = wdColorAutomatic Then selection.Shading.BackgroundPatternColor = wdColorAutomatic End If Next oPara Application.ScreenUpdating = True End Sub Last edited by vivka; 08-17-2023 at 09:53 PM. |
#3
|
|||
|
|||
![]()
Oh, alright! I've uploaded an example file with the text that I talked about, if that helps.
Quote:
|
#4
|
|||
|
|||
![]()
Hi! Is your example is what you want to get or what you don't want to get but get?
|
#5
|
|||
|
|||
![]()
This code replaces automatic shading with the page color set in your example document:
Code:
Sub Another_Go() ' Application.ScreenUpdating = False 'If the selection includes tables, error 4605 will be returned. 'Thus an error handler is needed: On Error Resume Next For Each oPara In ActiveDocument.range.Paragraphs oPara.range.Select selection.End = selection.End - 1 selection.Shading.BackgroundPatternColor = -654246042 Next oPara Application.ScreenUpdating = True End Sub |
#6
|
|||
|
|||
![]()
I知 pretty sure you値l find that the page color has only been set to make the text shading visible. Kinda hard to see white shading against a white background.
|
#7
|
|||
|
|||
![]()
Italophile, thank you for clearing up the misunderstanding. My n-th try:
Code:
Sub Test_Nth() Application.ScreenUpdating = False 'If the selection includes tables, error 4605 will be returned. 'Thus an error handler is needed: On Error Resume Next For Each oPara In ActiveDocument.range.Paragraphs oPara.range.Select selection.End = selection.End - 1 selection.Shading.BackgroundPatternColor = wdColorAutomatic Next oPara Application.ScreenUpdating = True End Sub |
#8
|
|||
|
|||
![]() Quote:
Quote:
Just in case, I added: Selection.HomeKey Unit:=wdStory (that is, Ctrl+Home) so that the cursor ends up in the beginning of the document. With that added, this works flawlessly. Full code, in case anyone wants it: Code:
Sub AutoOpen() ' ' AutoOpen Macro ' ' This macro opens itself (AutoOpen) automatically with every Word document that's opened normally ' Choose background colour (light green 2) ActiveDocument.Background.Fill.ForeColor.ObjectThemeColor = wdThemeColorAccent6 ActiveDocument.Background.Fill.ForeColor.TintAndShade = 0.6 ActiveDocument.Background.Fill.Visible = msoTrue ActiveDocument.Background.Fill.Solid ' Turn option 'Show background colors and images in Display view' on ActiveWindow.View.DisplayBackgrounds = True ' Change all text font to black colour ActiveDocument.Content.Font.Color = wdColorBlack ' Change all text and change "fill shading" background to no colour https://www.msofficeforums.com/word-vba/51216-change-fill-text-colour-colour.html With ActiveDocument.Content.ParagraphFormat .Shading.Texture = wdTextureNone .Shading.ForegroundPatternColor = wdColorAutomatic .Shading.BackgroundPatternColor = wdColorAutomatic End With ' Change all paragraphs with fill to no fill (from https://www.msofficeforums.com/word-vba/51216-change-fill-text-colour-colour.html) Application.ScreenUpdating = False 'If the selection includes tables, error 4605 will be returned. 'Thus an error handler is needed: On Error Resume Next For Each oPara In ActiveDocument.Range.Paragraphs oPara.Range.Select Selection.End = Selection.End - 1 Selection.Shading.BackgroundPatternColor = wdColorAutomatic Next oPara Application.ScreenUpdating = True Selection.HomeKey Unit:=wdStory End Sub |
![]() |
Tags |
fill, shading |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Change Text Colour/Box Shade if CheckBox is marked | cavals07 | Word VBA | 7 | 01-30-2023 11:05 AM |
![]() |
trevorc | Excel | 2 | 06-30-2021 12:27 PM |
Text box fill colour changes when pasted to new file | ParishPete | Publisher | 0 | 06-21-2019 12:47 AM |
Change text colour for content control labels? | Toe | Word | 1 | 01-17-2019 08:45 AM |
How to globally change default "pattern fill" color for all shapes in PP 2013 | tbach | PowerPoint | 1 | 01-31-2014 10:59 AM |