VBA store msoThemeColor in variable

JKo_FinanceUse

I am looking to store mso theme colors in a variable so that the chart colors and patterns can change dynamically (variable Th in this situation). Here is my current code:

Dim Th As Long
Th = "msoThemeColorAccent" & ActiveCell.Offset(-5, 0)
If ActiveCell = "Realized" Then
    ActiveChart.SeriesCollection(Srs).Select

    With Selection.Format.Fill
        .ForeColor.ObjectThemeColor = Th
        .Solid
    End With
    With Selection.Format.Line
       .ForeColor.ObjectThemeColor = Th
    End With
End If

I'm thinking the problem here is that I am not using the correct Dim categorization. I've seen questions on here on storing RGB as variables (using Dim Long seemed to be the solution) but nothing on msoThemeColors yet. Thanks and let me know if I can provide any other details!

Scott Holtzman

Since msoThemeColorAccent is an enumeration, the below refactored code will work.

Dim lThemeColor As Long
lThemeColor = ActiveCell.Offset(-5, 0) + 4
'msoThemeColor1 enum is 5, 2 is 6, 3 is 7 ... so add 4 to the value 

If ActiveCell = "Realized" Then

    With ActiveChart.SeriesCollection(Srs).Format
        With .Fill
            .ForeColor.ObjectThemeColor = lThemeColor
            .Solid
        End With
        With .Line
           .ForeColor.ObjectThemeColor = lThemeColor
        End With
    End With

End If

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Store a closure as a variable in Swift

From Dev

Store javascript variable into array

From Dev

How to store ERRORLEVEL in a variable?

From Dev

Store a variable in a external file

From Dev

Store jquery selector in variable

From Dev

Store location of cell address to variable in VBA

From Dev

Store a long variable in EEPROM

From Dev

How do I store a variable permanently in a Word 2010 document using VBA?

From Dev

Store column result in variable

From Dev

YAML: Store array as variable

From Dev

Store an operator in a variable with Ruby

From Dev

How to store and recall a variable?

From Dev

Store variable using sessions

From Dev

Angular store variable in service

From Dev

Jquery - Store text in a variable

From Dev

How to Store Variable in Excel Application Memory VBA

From Dev

Store JSON data into a variable

From Dev

Excel VBA: To store 'a word in a string' into a variable if that word is there in an array of strings

From Dev

Store function result into variable

From Dev

Store several elements on a variable

From Dev

Python - Store function in variable

From Dev

store awk output in variable

From Dev

vba store recordset as integer variable

From Dev

What is largest value (number) that I can store in an Excel VBA variable?

From Dev

Store into variable result of function VBA

From Dev

VBA: Retrieve data from a filter and store it in a variable

From Dev

Store variable in another variable

From Dev

Store Each Numeric Value in an Array to a Variable in VBA in PowerPoint

From Dev

Using VBA, Not able to store the cell value in a variable and throws 1004 error