Solved

Excel 2013 Shapes Color mystery

Posted on 2014-12-01
3
159 Views
Last Modified: 2014-12-06
What I'm trying to do is
ActiveSheet.Shapes("shpPart1").Fill.ForeColor = 13998939

Open in new window


but I get a Type Mismatch error.

Can someone please explain why I'm getting this? I see that the ForeColor is a long integer but I get a Type Mismatch error. So I tried String data type and get the same error.

Sub PartShapesTEST2()

    Dim s As Shape
    Dim lngColor As Long
    
    Set s = ActiveSheet.Shapes("shpPart1")
    
    lngColor = s.Fill.ForeColor
    
    s.Fill.ForeColor = lngColor
    
End Sub

Open in new window

0
Comment
Question by:hindersaliva
3 Comments
 

Author Comment

by:hindersaliva
ID: 40474227
Solved it!

Should be

s.Fill.ForeColor.RGB = lngColor

even though the color is not in RGB ie. not as in (255, 0, 0)
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 250 total points
ID: 40474859
The ForeColor property actually returns a ColorFormat object, but because you have declared lngColor as Long, the VB engine converts to the Long RGB representation.

The Long number you are seeing is actually an RGB value, but uses a mathematical equation (R*256^2 + G*256 + B) to convert it.

An alternative to your original code would be as follows...

Sub PartShapesTEST2()

    Dim s As Shape
    Dim oColor As ColorFormat
    
    Set s = ActiveSheet.Shapes("shpPart1")
    
    Set oColor = s.Fill.ForeColor
    
    s.Fill.ForeColor = oColor
    
End Sub

Open in new window

0
 
LVL 5

Assisted Solution

by:Hakan Yılmaz
Hakan Yılmaz earned 250 total points
ID: 40475801
You can also change color this way,
YourShapeObject.Fill.ForeColor.RGB = RGB(redvalue 0-255, greenvalue 0-255, bluevalue 0-255)

RGB in the right hand side is a built in function that returns Long Integer number representing the color you gave.
So you can assign Long Integer value to a Long Integer property of an object.

You can use Object Browser in Excel (Shortcut F2) to see what type of object you should assign to a property of an another object.
If you can't find enough explanations in Object Browser, you may look at Excel 2010 Developer Reference or Excel 2013 Developer Reference.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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…

746 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

17 Experts available now in Live!

Get 1:1 Help Now