I've checked the link in post 4 and I found out that it cannot be used in db since it changes all buttons color to same color. I have different buttons with different colors. If changed it to other color scheme (using acces theme), each button's color is changed to respective accent and that is what I want.For info, the utility created by DaveGri (post #4 link) doesn't actually use the built-in Access theme feature though it has similar results
Peter Cole's utility (link in post #5) does use Access themes
Yes, selected value will be saved locally and will not be replaced with FE update.Be careful about allowing the user to customize the FE unless you are storing the customizations in a table so they can be reapplied. Otherwise, when you replace the FE with an updated version, the user's customizations will be lost.
Private Const sThemeName As String = "MyColorTheme2.xml"
Sub CreateColorTheme()
'Customises the color theme applied to current workbook and then saves it to the user's theme folder
Dim sPath As String
sPath = Application.TemplatesPath & "\Document Themes\Theme Colors\"
With ActiveWorkbook.Theme
.ThemeColorScheme(msoThemeDark1).RGB = 0 'Black
.ThemeColorScheme(msoThemeLight1).RGB = RGB(255, 255, 255) 'White
.ThemeColorScheme(msoThemeDark2).RGB = RGB(65, 64, 66) 'Charcoal
.ThemeColorScheme(msoThemeLight2).RGB = RGB(75, 207, 174) 'Mint
.ThemeColorScheme(msoThemeAccent1).RGB = RGB(92, 116, 132) 'Blue Grey
.ThemeColorScheme(msoThemeAccent2).RGB = RGB(110, 194, 197) 'Teal
.ThemeColorScheme(msoThemeAccent3).RGB = RGB(245, 121, 53) 'Sol
.ThemeColorScheme(msoThemeAccent4).RGB = RGB(212, 20, 90) 'Magenta
.ThemeColorScheme(msoThemeAccent5).RGB = RGB(34, 181, 115) 'Leaf Green
.ThemeColorScheme(msoThemeAccent6).RGB = RGB(42, 187, 224) 'Azure
.ThemeColorScheme(msoThemeHyperlink).RGB = RGB(52, 152, 219) 'Sky Blue
.ThemeColorScheme(msoThemeFollowedHyperlink).RGB = RGB(100, 49, 141) 'Grape
.ThemeColorScheme.Save Filename:=sThemeName 'Creates/Overwrites
End With
MsgBox sPath & sThemeName, vbOKOnly, "Color Theme Created"
End Sub
Sub ApplyColourTheme() ' for Excel
Dim sPath As String
sPath = Application.TemplatesPath & "\Document Themes\Theme Colors\" & sThemeName
ActiveWorkbook.Theme.ThemeColorScheme.Load sPath
End Sub
Yes I saw it. But is accde and couldn't figure aout how to ise this in my db. It adds theme but I think one have to change theme using access ribbon which in my db are hidden along with the access window.Did you try the link I provided in post #5?
Yes I tried it in accdb but ActiveWorkbook code did not work in access file.Try the code with an .accdb. If it works, then you know you cannot use it in an .accde.
Sorry for confusion. The code I posted in my former post was taken from excel forum and that code works perfectly but I cannot convert it to Access. I thought you're referring to that code in your following postGuess I'm not sure how Excel got into this discussion. I thought we were talking about Access. I would not expect ActiveWorkbook to work in Access since that is Excel syntax.
If you're not referring to that code I posted then please tell me which code are you referring to so that I can try that.Try the code with an .accdb. If it works, then you know you cannot use it in an .accde.
Public Sub TESTAddNewThemeToMSysResources()
AddNewThemeToMSysResources "C:\Program Files\Microsoft Office\root\Document Themes 16\Slice.thmx"
End Sub
Public Sub AddNewThemeToMSysResources(strNewThemeFullName As String)
Dim rst As DAO.Recordset
Dim rstNewThemeData As DAO.Recordset2
Dim strExt As String
Dim strNewThemeName As String
Dim lngPosBS As Long
strNewThemeName = Replace(Mid(strNewThemeFullName, InStrRev(strNewThemeFullName, "\") + 1), ".thmx", "")
Debug.Print strNewThemeName
Stop
Set rst = CodeDb.OpenRecordset("SELECT * FROM MSysResources WHERE 1 = 0")
rst.AddNew
rst.Update
rst.Bookmark = rst.LastModified
rst.Edit
rst!Extension = "thmx"
rst!Name = strNewThemeName
rst!Type = "thmx"
Set rstNewThemeData = rst.Fields("Data").Value
rstNewThemeData.AddNew
rstNewThemeData.Fields("FileData").LoadFromFile strNewThemeFullName
rstNewThemeData.Update
rst.Update
rst.Close
End Sub
So nice of you for such an explained post. I will check and update here.From post #9 I see that you appreciate how different buttons can use different Accent numbers to give the different colors.
Access stores themes in the hidden system table MsysResources as an Attachment unlike Excel Word etc that store the XML of the theme.
in XML text.
Each time you select a theme from the ribbon Theme Gallery Access adds an entry to the MSysResources table. If the Theme has already been stored it will be prefixed with a number followed by underscore. eg The first use of Facet will have the name Facet, selecting again will add the name 1_Facet
The names will remain in MSysResources until a compact and repair, eliminating all but the last theme.
The property to be read or set is
CurrentDb.Properties("Theme Resource Name")
The spaces are required.
Reading the property will show the current Theme name
If the property is set to a new theme name and you close and reopen the database the new theme colors will show if that theme name exists in MSysresources. If that theme has never been used or the db has been compacted there will be an error.
To prevent the error the theme would need to be added to MSysResources. As the theme is stored in an attachment field you have to use VBA, you can't use an SQL Append on attachments.
The following code will add Slice to MSysResources.
(If running Access 2010 or 2013 you will need to adjust the 16.
Public Sub TESTAddNewThemeToMSysResources()
AddNewThemeToMSysResources "C:\Program Files\Microsoft Office\root\Document Themes 16\Slice.thmx"
End Sub
Public Sub AddNewThemeToMSysResources(strNewThemeFullName As String)
Dim rst As DAO.Recordset
Dim strNewThemeData As DAO.Recordset2
Dim strExt As String
Dim strNewThemeName As String
Dim lngPosBS As Long
strNewThemeName = Replace(Mid(strNewThemeFullName, InStrRev(strNewThemeFullName, "\") + 1), ".thmx", "")
Debug.Print strNewThemeName
Stop
Set rst = CodeDb.OpenRecordset("SELECT * FROM MSysResources WHERE 1 = 0")
rst.AddNew
rst.Update
rst.Bookmark = rst.LastModified
rst.Edit
rst!Extension = "thmx"
rst!Name = strNewThemeName
rst!Type = "thmx"
Set strNewThemeData = rst.Fields("Data").Value
strNewThemeData.AddNew
strNewThemeData.Fields("FileData").LoadFromFile strNewThemeFullName
strNewThemeData.Update
rst.Update
rst.Close
End Sub
This works for the standard themes but if allowing users to change the applied theme you will need to create custom themes using the fonts that you use in your database otherwise you might have the "Fit" problem for text that Pat describes.
It is easy to create custom themes with different fonts using my Free TMDThememaker.
Custom themes are stored in the users profile
C:\Users\usersname\AppData\Roaming\Microsoft\Templates\Document Themes
They are XML so you could store a copy of each custome theme in a table in your database then on opening the form that allows the user to change theme copy the XML to the Documents Themes folder then add the file as the attachment using a modified version of the above.
For other reading this post this code is only needed as the Ribbon is not available.
This works in accde.
Glad to be of help.So nice of you for such an explained post. I will check and update here.
Thanks again.