Get theme colors?

N

Nikolay Belyh

Given a theme name, how do I get the colors for it? (programmatically)
I.e. how do I get the actual colors for the "FillColor",
"AccentColor1", "AccentColor2", etc?

Kind regards, Nikolay.
 
J

JuneTheSecond

Hi,

Page.ThemeColors property gets name of theme colos.
Cell.FormulaU property gets name of color.

for example
Debug.Print ActivePage.ThemeColors
Debug.Print ActivePage.Shapes(1).Cells("FillBkgnd").FormulaU

Best Regards
 
N

Nikolay Belyh

Thank you for reply.

But what I need is a slightly different thing. I'll try to explain
what I need.
I want to implement kinda "visual" Visio theme selector in my own
dialog/form. And I want to create a window (list) that contains theme
previews in that dialog. It shall look like visio's pane "Theme
colors", but it shall be located in my own dialog/form.

Now, I am able to get all theme names (using Document.GetThemeNames)
The question is, how, given a theme name, do I get theme colors
themselves to paint items of my list?

Kind regards, Nikolay.
 
J

JuneTheSecond

I am not sure this is right answer.

The shape sheet of themecolor has user defined cells.
Here are the 12 theme colors for tex, line, fill etc., defined by RGB
functions

Next steps may be need to open the shape sheet.

Copy any theme color icon as user define theme color.
Change the hidden property of all masters in the document turn into false.
Open drawing stencil window, double click the master of theme color, open
shape sheet.

Hope this help.
 
N

Nikolay Belyh

Thanks, but won't this "hardcode" the theme colors? Means, if the next
version of Visio will change the list of themes/theme colors (for
example), OR if a end-user has his own theme defined in a document,
then this method will cease to function... Won't it?

Meantime I came to some sort of "weird" implementation eventually...
Now I ended up creating a "fake" invisible page in a document, putting
there that "6 boxes and a line" picture (one that can be found in
Visio's "Themes" pane) where each box is painted with particular theme
color, then repeatedly applying all available themes to that invisible
page one-by-one, while taking a series of "screen-shots" of that
invisible page, using Page.Picture property - it generates a nice
scalable EMF images that can be rendered in a dialog/form as "theme
thumbnails", and finally deleting that fake page... Fuf.. :)

But hopefully someone can suggest a more "straightforward" approach?

Kind regards, Nikolay.
 
J

JuneTheSecond

This is not also the right answer.
But, I've made an example to get fill fore ground colors for all ThemeColors.
Here, GetThemeNames is the example code in Visio help for "GetThemeNamesU"
method. Added 2 arrays that contains theme names.
And shp is a dummy shape that has theme color, simple rectangle or any
other, selected on the window.

Option Explicit
Dim aThemeColors(0 To 100) As String
Dim aThemeEffects(0 To 100) As String

Sub getThemeFillForegnd()
Dim shp As Visio.Shape
GetThemeNames
Set shp = ActiveWindow.Selection(1)
Dim I As Long
For I = 1 To 35
shp.Cells("User.msvThemeColors") = I
Debug.Print I, aThemeColors(I), shp.Cells("FillForegnd").ResultStr("")
Next
End Sub
Public Sub GetThemeNames()

Dim astrNames() As String
Dim strThemeName As String
Dim intArrayCounter As Integer

ActiveDocument.GetThemeNamesU visThemeTypeColor, astrNames
For intArrayCounter = LBound(astrNames) To UBound(astrNames)
strThemeName = astrNames(intArrayCounter)
aThemeColors(intArrayCounter) = strThemeName
' Debug.Print intArrayCounter, strThemeName
Next

' Debug.Print "-------------------------------------------"

ActiveDocument.GetThemeNamesU visThemeTypeEffect, astrNames
For intArrayCounter = LBound(astrNames) To UBound(astrNames)
strThemeName = astrNames(intArrayCounter)
aThemeEffects(intArrayCounter) = strThemeName
' Debug.Print intArrayCounter, strThemeName
Next

End Sub
 
J

JuneTheSecond

And exanding my example, line colors and text colrs are obtained.
Sub getThemeFillForegnd()
getThemeColor "FillForegnd"
End Sub
Sub getThemeLineColor()
getThemeColor "LineColor"
End Sub
Sub getThemeTEXTColor()
getThemeColor "Char.Color"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top