![]() |
|
#1
|
|||
|
|||
![]()
Hello! So I've been given various Word files which have, in all the document, the fill "shading" paragraph colour, in white. What I want to do is place a VBA Macro in AutoOpen so that, when I open a document, the fill is changed to no colour. So far, I've come up with a method that goes about it by selecting all text and then changing it, but I'm sure there must be a better way of doing this for all the document. What I have is:
Code:
Selection.WholeStory Selection.Shading.Texture = wdTextureNone Selection.Shading.ForegroundPatternColor = wdColorAutomatic Selection.Shading.BackgroundPatternColor = wdColorAutomatic Maybe something similar to this (change font colour to black) could be done? Code:
' Change all text font to black colour ActiveDocument.Content.Font.Color = wdColorBlack |
#2
|
|||
|
|||
![]()
Hello, darkmaster006! My limited knowledge of VBA says that your code is doing exactly what is expected:
selection.WholeStory selection.Shading.BackgroundPatternColor = wdColorAutomatic Maybe, this forum's gurus will have different opinions. |
#3
|
|||
|
|||
![]()
You can avoid selecting the text by using the following:
Code:
With ActiveDocument.Content.ParagraphFormat .Shading.Texture = wdTextureNone .Shading.ForegroundPatternColor = wdColorAutomatic .Shading.BackgroundPatternColor = wdColorAutomatic End With |
#4
|
|||
|
|||
![]()
Thank you both!
Quote:
For texts that are all formatted as "one paragraph", this works perfectly. Example: ![]() This gets "cleaned" well, like this: ![]() Yet, when I get a text that has "multiple paragraphs", like this: ![]() Nothing gets changed. Do you have any idea how to do it to texts like these too? The only way I've found, so far, is to paste them to another document, without formatting. It's not ideal, but it's what I've found worked so far. There must be an easier way to do it in-document and with macros, like the code above. |
#5
|
|||
|
|||
![]()
Hi! Back to my previous answer.
The both will work: Code:
Sub Test() selection.WholeStory selection.Shading.Texture = wdTextureNone selection.Shading.ForegroundPatternColor = wdColorAutomatic selection.Shading.BackgroundPatternColor = wdColorAutomatic selection.Collapse 1 'this deselects the text End Sub Code:
Sub Test() With ActiveDocument.range .Shading.Texture = wdTextureNone .Shading.ForegroundPatternColor = wdColorAutomatic .Shading.BackgroundPatternColor = wdColorAutomatic End With End Sub |
#6
|
|||
|
|||
![]() Quote:
Sadly, it seems that this leaves it with a complete white background (can't figure out why): ![]() |
#7
|
|||
|
|||
![]()
Without seeing the document, it is only possible to guess.
|
#8
|
|||
|
|||
![]()
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. |
#9
|
|||
|
|||
![]()
Oh, alright! I've uploaded an example file with the text that I talked about, if that helps.
Quote:
|
#10
|
|||
|
|||
![]()
Hi! Is your example is what you want to get or what you don't want to get but get?
|
#11
|
|||
|
|||
![]()
Darkmaster006, I'm glad that you are glad! As for the page color that is easy for eyes, I prefer sky blue. And of course, thank you for your sharing the full code!
|
#12
|
|||
|
|||
![]()
Thank you! And, of course, there might always be people lurking who might have a use for the code. As for sky blue, you mean like the one on the forum? I do admit it's pretty good too!
|
![]() |
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 |