PDA

View Full Version : Include theme colors in an add-in



cplindem
05-30-2014, 10:35 AM
Is there a way to include custom theme colors in an add-in?

I want my macro to change the user's theme colors. When I try recording a macro and manually changing the theme colors, the code comes out just loading the ThemeColorScheme I just created (i.e. it can't really record my actions). So what I need is some way to place a custom ThemeColorScheme (xml file) on each user's hard drive through my add-in. Is such a thing possible?


Thanks

Jan Karel Pieterse
06-02-2014, 09:05 AM
Theme colors are not part of an Excel file, but rather special xml files in a special folder in your Office installation:

C:\Program Files (x86)\Microsoft Office\Document Themes 14

There is a utility to create your own, but it isn't very simple to do:

http://openxmlthemebuilder.codeplex.com/

cplindem
06-02-2014, 10:54 AM
Thanks for the reply.

I actually already have my own theme (THMX) file. What I want is for my add-in macro to apply this theme. My code would be:


ActiveWorkbook.ApplyTheme ("C:\Program Files (x86)\Microsoft Office\Document Themes 14\Custom.thmx")

I was hoping the THMX (or XML) file could somehow be included in the add-in (because users won't have it), but maybe this just is not possible.

Jan Karel Pieterse
06-02-2014, 10:47 PM
Well, you could paste the content of the thmx file in your addin file and use a bit of code to push it out to a textfile.

cplindem
06-03-2014, 08:24 AM
Do I have this right?

1. Edit the thmx file in notepad
2. Copy the text into VBA
3. Add code to write this text into a txt file
4. Rename the txt file to thmx (in VBA?)

Jan Karel Pieterse
06-03-2014, 08:34 AM
I would just paste it into a sheet, read the sheet from VBA later on and write to thmx file.

cplindem
06-03-2014, 09:36 AM
There is no sheet (this is an add-in). So wouldn't I have to have the thmx text inside the VBA code already?

Jan Karel Pieterse
06-03-2014, 10:51 AM
I assumed this is an Excel add-in, which can have as many sheets as you like. I always edit my tools as normal workbooks, when done I save-as to add-in filetype.

cplindem
06-03-2014, 03:06 PM
Huh. I must be misunderstanding some fundamental behavior of add-ins. I created mine in the way you describe (wrote the macro in a module within a workbook, then saved as xlam).
Now that I have it installed I can call it anytime by pressing the associated button I added to the ribbon. But I can't see any sheets associated with it. Are they just hidden or....?

Jan Karel Pieterse
06-03-2014, 10:16 PM
You can toggle the visibility of an add-in by turning the IsAddin property of the Thisworkbook module to true/false. Do set it back to false before saving again.
So basically yes, an addin is "just" a hidden workbook.

cplindem
06-04-2014, 09:13 AM
Cool. That is very helpful.

Thank you for all the assistance.