473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to make this code change the font colour to white if black cell colour is chosen

2
Hi,

Can someone tell me what to put in this code so that if a user selects 0 (Black) then make the font white (0) as my default colour is black on my Excel spreadsheet.
Expand|Select|Wrap|Line Numbers
  1. Private Type CHOOSECOLOUR 
  2. lStructSize As Long 
  3. hwndOwner As Long 
  4. Hinstance As Long 
  5. rgbResult As Long 
  6. lpCustColors As String 
  7. flags As Long 
  8. lCustData As Long 
  9. lpfnHook As Long 
  10. lpTemplateName As String 
  11. End Type 
  12.  
  13. Declare Function ChooseColorA _ 
  14. Lib "Comdlg32" ( _ 
  15. lpChooseColor As CHOOSECOLOUR) _ 
  16. As Long 
  17. Declare Function FindWindowA _ 
  18. Lib "User32" ( _ 
  19. ByVal lpClassName As Any, _ 
  20. ByVal lpWindowName As String) _ 
  21. As Long 
  22.  
  23. Function SelectColour(Code_RGB) As Boolean 
  24. Dim CColor As CHOOSECOLOUR 
  25. Dim CustColors As String * 16 
  26. With CColor 
  27. .lStructSize = 36 
  28. .hwndOwner = FindWindowA(0&, Application.Caption) 
  29. .lpCustColors = CustColors 
  30. .flags = 2 
  31. End With 
  32. If ChooseColorA(CColor) = 0 Then Exit Function 
  33. Code_RGB = CColor.rgbResult 
  34. SelectColour = True 
  35. End Function 
  36.  
  37. Public Function RGBRed(RGBCol As Long) As Integer 
  38. '// Return the Red component from an RGB Color 
  39. RGBRed = RGBCol And &HFF 
  40. End Function 
  41.  
  42. Public Function RGBGreen(RGBCol As Long) As Integer 
  43. '// Return the Green component from an RGB Colour 
  44. RGBGreen = ((RGBCol And &H100FF00) / &H100) 
  45. End Function 
  46.  
  47. Public Function RGBBlue(RGBCol As Long) As Integer 
  48. '// Return the Blue component from an RGB Colour 
  49. RGBBlue = (RGBCol And &HFF0000) / &H10000 
  50. End Function 
  51.  
  52. Sub Theme() 
  53.  
  54. If Sheets("Tasks").ProtectContents = True Then 
  55. Sheets("Tasks").Unprotect ("*******") 
  56. End If 
  57. If Sheets("Stats").ProtectContents = True Then 
  58. Sheets("Stats").Unprotect ("*******") 
  59. End If 
  60. If Sheets("User Guides").ProtectContents = True Then 
  61. Sheets("User Guides").Unprotect ("*******") 
  62. End If 
  63. 'If Sheets("Stats").ProtectContents = True Then 
  64. Sheets("Stats").Unprotect ("*******") 
  65. 'End If 
  66.  
  67. MsgBox "Please select a new heading colour using the popup colour selector and then press OK.", 64, "Change your heading colour." 
  68. Dim Code_RGB As Long 
  69. Dim myRange1 As Range, myRange2 As Range, myRange3 As Range, myRange4 As Range, myRange5 As Range, myRange6 As Range, myRange7 As Range 
  70. If Not SelectColour(Code_RGB) Then Exit Sub 
  71. Set myRange1 = ActiveSheet.Range("A4,A5,A6,B6,C1,C6,D6,E1,E6,F1,F6,G1,G6,H1,H2,H3,H4,H5,H6,I6,J6,K2,K3,K4,K5,K6,L6,M6,N2,N3,N4,N5,N6,O6,P6,Q1,Q2,Q4,Q5,Q6,R1,R6,S1,S6,T6,U6,V6") 
  72. Set myRange2 = Worksheets("Stats").Range("A2,A12,B2,B3,B4,B5,B7,B12,C7,C12,D7,D12,E7,E8,E9,E10,E11,E12,F12,(G12:G214)") 
  73. Set myRange7 = Worksheets("User Guides").Range("A1,A2,B2") 
  74. If ActiveSheet.ProtectContents = True Then 
  75. ActiveSheet.Unprotect ("*******") 
  76. End If 
  77. myRange1.Interior.Color = Code_RGB 
  78. myRange2.Interior.Color = Code_RGB 
  79.  
  80. Set myRange1 = Nothing 
  81. Set myRange2 = Nothing 
  82. Set myRange6 = Nothing 
  83. Set myRange7 = Nothing 
  84.  
  85. If Sheets("Tasks").ProtectContents = False Then 
  86. Sheets("Tasks").Protect ("*******") 
  87. End If 
  88. If Sheets("Stats").ProtectContents = False Then 
  89. Sheets("Stats").Protect ("*******") 
  90. End If 
  91. If Sheets("User Guides").ProtectContents = False Then 
  92. Sheets("User Guides").Protect ("*******") 
  93. End If 
  94. 'If Sheets("Stats").ProtectContents = True Then 
  95. 'Sheets("Stats").Unprotect ("*******") 
  96. 'End If 
  97.  
  98. ActiveSheet.Protect ("*******") 
  99.  
  100. End Sub 
  101.  
Hope someone can help me on this little problem as in the test people were choosing black, cuz it's cool..
Feb 9 '07 #1
0 1578

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Keith | last post by:
I have downloaded some sample code from the net to display a calendar etc. The code is below. How can I modify this code so that when called in a popup window and a date is clicked, that date...
6
by: Louise | last post by:
Hi I have written an HTML pages which does not have any colour specifying tags as far I know. When I view this in an Microsoft internet explorer browser it appears with a white background and...
14
by: Viken Karaguesian | last post by:
Hello all, It stinks being a newbie! One thing that I'm not sure about with CSS is: where is the "proper" place to put font attibutes? This has me a little confused. Take the below style sheet...
3
by: netsurfer | last post by:
Hi: I am working on a project and need assistance, and would really appreciate any feedback on it. First part I'm banging my head against the wall on is about the amounts of the Amount fields...
0
by: Annick | last post by:
I would like to change the format of a cell depended on the value of the data. I wrote the following script, which works fine. .. . . Function function_ChangeFormat(ByVal value_01) Dim...
5
by: Novice Computer User | last post by:
Hi. Can somebody PLEASE help. Here is a .php script. Right now, the minimum amount of time (i.e. duration) allowed is 1 month. However, I want to be able to reduce the minimum amount of time to...
7
by: xformer | last post by:
Hello everybody, today I was working on a web site when I found a strange effect. Take the following html document: ----begin---- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...
53
by: Jonas Smithson | last post by:
In his book "CSS: The Definitive Guide" 2nd edition (pgs. 116-117), Eric Meyer has an interesting discussion about "font-size-adjust" that was evidently dropped in CSS 2.1 due to browser...
3
by: CSharper | last post by:
Is it possible to selectivly change the color of an item in text. I saw ForeColor option, but it changes the color of all the items. If it is not possible, is there any other control list listbox...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.