none
Create Word Colour Theme VBA RRS feed

  • Question

  • Just wondering if there is a means to programically create a theme colour in VBA.  I want to imbed the code into the word template, previously I had seperately created the theme file and wrapped that and the template into a self extracting rar file but ran into internal network issues if the user didn't have significant rights to run .exe files.  A work around was to save the theme file on a common internal server location which again worked for a period but now we have several external agents who need to use the template but don't have access to the server.  Any help is greatly appreciated.

    Dangerous... #UpUpCronulla

    Tuesday, April 23, 2013 6:44 AM

Answers

  • Hi DangerDraper

    Try the following to set a color in the theme.

    Dim tcTheme As OfficeTheme
    Dim tcThemecolorscheme As ThemeColorScheme
    Dim tcThemeColor As ThemeColor
    Set tcTheme = ActiveDocument.DocumentTheme
    Set tcThemecolorscheme = tcTheme.ThemeColorScheme
    Set tcThemeColor = tcThemecolorscheme.Colors(msoThemeAccent1)
    tcThemeColor.RGB = RGB(0, 255, 0)
    tcThemecolorscheme.Colors(msoThemeAccent1) = tcThemeColor
    tcThemecolorscheme.Save ("C:\myThemeColorScheme.xml")

    NOTICE:
    Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose.

    Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

    Articles:
    =====
    OfficeTheme Object (Office)
    http://msdn.microsoft.com/en-us/library/office/ff860320.aspx

    OfficeTheme Members (Office)
    http://msdn.microsoft.com/en-us/library/office/ff865516.aspx

    Document.DocumentTheme Property (Word)
    http://msdn.microsoft.com/en-us/library/office/ff840566.aspx

    Best Regards,

    Donald M.
    Microsoft Online Community Support
    --------------------------------------------------------------------------------
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Marked as answer by DangerDraper Wednesday, May 15, 2013 5:02 AM
    Tuesday, May 14, 2013 5:43 PM

All replies

  • Hi DangerDraper,

    Have a look at this link, please:

    Document.ApplyTheme Method (Word)

    Have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, April 25, 2013 5:47 AM
    Moderator
  • Hi DangerDraper,

    I temporarily marked the reply as answer and you can unmark it if it provides no help.
    Please feel free to let us know if you have any concern.

    Thanks for your understanding and have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 2, 2013 1:29 PM
    Moderator
  • Yoyo, sorry but I've been overseas and only just returned to the office.  Just having a quick browse it appears that the Theme must already exist to use this method, what I'm chasing is a means to set each specific swatch colour ie Follwed Hyperlink = [R12, G99, B54] , Major and Minor Fronts, Line Styles ect. via VBA.  I started to have a play around and in true MS form couldn't get the supplied help code to work.  Eventually I had

    Sub TestA()
    
        Dim TestA As String
        
        TestA = ""
        TestA = ActiveDocument.ActiveTheme
        MsgBox TestA
        'from MS Office help page http://msdn.microsoft.com/en-us/library/office/ff835740(v=office.14).aspx
            On Error GoTo handler
            ActiveDocument.ApplyTheme "Elemental 001"
                
    handler:
            If Error <> 0 Then
                ActiveDocument.ApplyDocumentTheme _
                "C:\Program Files (x86)\Microsoft Office\Document Themes 14\Foundry.thmx"
                'Swap in "C:\Program Files\Microsoft Office\Document Themes 14\Foundry.thmx" for regular users of Office 2010
            End If
            
        TestA = ""
        TestA = ActiveDocument.ActiveTheme
        MsgBox TestA
        
    End Sub
    
    with funny results. The string value which I thought would be the Theme Name kept returning odd values, well atleast not the correct Theme nnn value that I expected. It would constantly return "Elemental 001" even after the theme had visiably changed. Strange.... Anyhow, it would seem to be one of those things that MS doesn't want you to do unless anyone else has a work around???

    Dangerous... #UpUpCronulla

    Tuesday, May 14, 2013 8:42 AM
  • Welcome back.

    I'm trying to involve some senior engineers into the issue. It takes some time. Your patience will be greatly appreciated.

    Thanks for your understanding and have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 14, 2013 9:33 AM
    Moderator
  • Hi DangerDraper

    Try the following to set a color in the theme.

    Dim tcTheme As OfficeTheme
    Dim tcThemecolorscheme As ThemeColorScheme
    Dim tcThemeColor As ThemeColor
    Set tcTheme = ActiveDocument.DocumentTheme
    Set tcThemecolorscheme = tcTheme.ThemeColorScheme
    Set tcThemeColor = tcThemecolorscheme.Colors(msoThemeAccent1)
    tcThemeColor.RGB = RGB(0, 255, 0)
    tcThemecolorscheme.Colors(msoThemeAccent1) = tcThemeColor
    tcThemecolorscheme.Save ("C:\myThemeColorScheme.xml")

    NOTICE:
    Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose.

    Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

    Articles:
    =====
    OfficeTheme Object (Office)
    http://msdn.microsoft.com/en-us/library/office/ff860320.aspx

    OfficeTheme Members (Office)
    http://msdn.microsoft.com/en-us/library/office/ff865516.aspx

    Document.DocumentTheme Property (Word)
    http://msdn.microsoft.com/en-us/library/office/ff840566.aspx

    Best Regards,

    Donald M.
    Microsoft Online Community Support
    --------------------------------------------------------------------------------
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Marked as answer by DangerDraper Wednesday, May 15, 2013 5:02 AM
    Tuesday, May 14, 2013 5:43 PM
  • Thanks Donald, that worked a treat.  Now I just have to have a play around to build the Font and Effects aspects of the Theme.  Thanks again.

    Dangerous... #UpUpCronulla

    Wednesday, May 15, 2013 5:01 AM
  • DangerDraper

    I'm glad I could help.
    Just for your references you should be able to get to the Fonts through the Theme's "ThemeFontScheme" property

    Articles:
    =====
    OfficeTheme.ThemeColorScheme Property (Office)
    http://msdn.microsoft.com/en-us/library/office/ff860546.aspx

    ThemeColorScheme Members (Office)
    http://msdn.microsoft.com/en-us/library/office/ff860305.aspx

    ThemeColor Members (Office)
    http://msdn.microsoft.com/en-us/library/office/ff862845.aspx

    OfficeTheme.ThemeFontScheme Property (Office)
    http://msdn.microsoft.com/en-us/library/office/ff862826.aspx

    ThemeFontScheme Members (Office)
    http://msdn.microsoft.com/en-us/library/office/ff861446.aspx

    ThemeFonts Members (Office)
    http://msdn.microsoft.com/en-us/library/office/ff861229.aspx

    ThemeFont Members (Office)
    http://msdn.microsoft.com/en-us/library/office/ff860900.aspx

    OfficeTheme.ThemeEffectScheme Property (Office)
    http://msdn.microsoft.com/en-us/library/office/ff865234.aspx

    ThemeEffectScheme Members (Office)
    http://msdn.microsoft.com/en-us/library/office/ff861504.aspx

    Best Regards,

    Donald M.
    Microsoft Online Community Support
    --------------------------------------------------------------------------------
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Wednesday, May 15, 2013 2:33 PM