Solved

VB.net Excel Add-In RGB Color

Posted on 2013-06-19
3
561 Views
Last Modified: 2013-06-20
Hi

I have used the following code to color cells in my VSTO Excel Add-in
Globals.ThisAddIn.Application.Selection.Interior.color = RGB(200, 160, 35)

I am now using a Color Dialog control on a form and the value of the selected color
is given in the following format "Color [A=255, R=128, G=64, B=0]"
How do I color a cell using this format?
0
Comment
Question by:murbro
3 Comments
 
LVL 81

Assisted Solution

by:byundt
byundt earned 250 total points
ID: 39260751
You might try parsing the string like this:
Sub ColorPicker()
Dim strColor As String
Dim iRed As Integer, iGreen As Integer, iBlue As Integer
strColor = "Color [A=255, R=128, G=64, B=0]"
iRed = Val(Mid(strColor, InStr(1, strColor, "R=") + 2))
iGreen = Val(Mid(strColor, InStr(1, strColor, "G=") + 2))
iBlue = Val(Mid(strColor, InStr(1, strColor, "B=") + 2))
Globals.ThisAddIn.Application.Selection.Interior.Color = RGB(iRed, iGreen, iBlue)
End Sub

Open in new window

Brad
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 250 total points
ID: 39261748
The ColorDialog returns a Color object which has R G and B properties so you should be able to use (assuming C is your returned Color object)
Globals.ThisAddIn.Application.Selection.Interior.Color = RGB(C.R, C.G, C.B)

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 39261768
Thanks for the help
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question