Solved

Excel 2013 Shapes Color mystery

Posted on 2014-12-01
3
162 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.Range Set 25 75
Multiple Open Excel Spreadsheets 12 39
Capture ESC press reliably without error 2 31
Excel cell formatting 5 27
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

785 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