Solved

VB.net Excel Add-In RGB Color

Posted on 2013-06-19
3
566 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

739 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