Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-28-2018, 01:04 PM
donaldadams1951 donaldadams1951 is offline VBA change font color to background color Windows XP VBA change font color to background color Office 2010 32bit
Advanced Beginner
VBA change font color to background color
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default VBA change font color to background color

I have a line of text in a document that is the title of a protected section. The section is protected so the end user can't edit the text in that section but they need to be able to delete the section. They delete the protected section by clicking a button on the ribbon. The macro finds the section by looking for the title and deletes the section if requested.

Since the end user does not want to see the title and I use the title as a "marker" I want to leave the title there but make it disappear. I tried to handle it by hiding the text but it works inconsistently. The next idea I came up with is to make the title font color the same as the background so it "disappears". Is there a VBA way make the text font color the same as the background? That way it would be there but not visible to the end user.
The text should also be invisible during printing.



If there is a better way to do this please let me know. Thanks
Reply With Quote
  #2  
Old 05-28-2018, 01:53 PM
slaycock slaycock is offline VBA change font color to background color Windows 7 64bit VBA change font color to background color Office 2016
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Hidden text will still be visible if you have the Show/Hide button selected. That's the backward P in the Home Tab.Paragraph group.

If you set the Show/Hide button to unselected in your macro to hide text then provided the user doesn't reset the Hide/Show button you should be OK.
Reply With Quote
  #3  
Old 05-29-2018, 03:48 PM
donaldadams1951 donaldadams1951 is offline VBA change font color to background color Windows XP VBA change font color to background color Office 2010 32bit
Advanced Beginner
VBA change font color to background color
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default Changed font color to white...

I have not been successful using font.hidden.

I changed the font.color to wdColorWhite when I start adding the title programmatically and change the font.color to wdColorBlack when finished inserting the title. It works but I'm wondering what I don't know that is going to come back and haunt me(?). We always print on white paper so I guess it works. The title no longer shows up on the screen or the printer.

Is there a way with VBA to find the background color so I can set the text font color to match the background color?
Reply With Quote
  #4  
Old 05-29-2018, 07:59 PM
macropod's Avatar
macropod macropod is online now VBA change font color to background color Windows 7 64bit VBA change font color to background color 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

Why would you want to leave the title behind, but hidden, if you're deleting all the related content?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-31-2018, 01:15 PM
donaldadams1951 donaldadams1951 is offline VBA change font color to background color Windows XP VBA change font color to background color Office 2010 32bit
Advanced Beginner
VBA change font color to background color
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default Leave but hide...

The user does not want to see the title but the title contains unique text that is the "marker" to identify the section that might need to be deleted with a macro. It can't be deleted manually by the user as the text is in a protected section that is read-only. I've not given all the details because I did not want to get into to all the whys and wherefores and just muddy the water when all I wanted was to know how to programmatically get the background color so the font color of the text would be the same and would disappear even if the user changed the background cover.
Reply With Quote
  #6  
Old 05-31-2018, 03:58 PM
jjfreedman jjfreedman is offline VBA change font color to background color Windows 10 VBA change font color to background color Office 2016
Advanced Beginner
 
Join Date: May 2012
Location: https://jay-freedman.info
Posts: 39
jjfreedman is on a distinguished road
Default

For manual setting of a specific paragraph, put the cursor in that paragraph and run this code:
Code:
Sub x()
    With Selection.Paragraphs(1).Range
        If .Shading.BackgroundPatternColor = wdColorAutomatic Then
            .Shading.BackgroundPatternColor = wdColorWhite
        End If
            
        .Font.TextColor.RGB = .Shading.BackgroundPatternColor
    End With
End Sub
For use in your macro that inserts the title, change "Selection.Paragraphs(1).Range" to the range of the paragraph that contains the title.

The If section is needed because setting both the font and the shading to Automatic gives black text on white background.
Reply With Quote
  #7  
Old 05-31-2018, 04:36 PM
macropod's Avatar
macropod macropod is online now VBA change font color to background color Windows 7 64bit VBA change font color to background color 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

Quote:
Originally Posted by donaldadams1951 View Post
The user does not want to see the title but the title contains unique text that is the "marker" to identify the section that might need to be deleted with a macro. It can't be deleted manually by the user as the text is in a protected section that is read-only.
Perhaps you could consider using a Custom Document Property or Document Variable to hold a value that an IF field in the body of the document can use to conditionally display/hide all of the applicable content. That way, there's no "marker" to be concerned with, and no need to worry about font colours, etc. If, for example, you create a Custom Document Property named 'MyProp', you could use a field coded as:
{IF{DOCPROPERTY MyProp}= 1 "Conditional Content to Show"}
The macro you're using to drive the process would then only need something like:
Code:
With ActiveDocument
  .CustomDocumentProperties("MyProp").Value = 0
  .Fields.Update
End With
to hide the content, and:
Code:
With ActiveDocument
  .CustomDocumentProperties("MyProp").Value = 1
  .Fields.Update
End With
to display it again after it's been hidden.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
background color, font color

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change excel background color, strange... sojiro Excel 7 04-18-2018 10:07 AM
Style Font Color: Background 1 gmgj Word 3 12-20-2017 04:00 PM
Advanced Font Color Manipulation In Word: Inserting another color than the surrounding text stuartg Word 1 02-20-2017 12:38 AM
VBA change font color to background color Remove white text background (keeping the font color and page color intact cc3125 Word 1 10-26-2015 06:44 PM
Font Color Question//.Replacement.Font.Color = 12611584 rsrasc Word VBA 3 09-05-2015 09:03 PM

Other Forums: Access Forums

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