Solved

VB.net Excel Add-In RGB Color

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

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

762 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

23 Experts available now in Live!

Get 1:1 Help Now