Solved

VB.net Excel Add-In RGB Color

Posted on 2013-06-19
3
555 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now