none
How to change the color sheme of Word? RRS feed

  • Question

  • How can I change the colorsheme of Microsoft Word programmatically using C#?

    I'm on Word 2010, I pass one of theme enums:

    Word.Document wddoc = (Word.Document)axFramerControl1.ActiveDocument;
    Word.Application wordApp = wddoc.Application;
    wordApp.ActiveDocument.DocumentTheme.ThemeColorScheme.Colors(MsoThemeColorSchemeIndex.msoThemeAccent4);

    But colorSheme doesnot change. 
    Where am I doing wrong?


    • Edited by _Sahar Thursday, July 3, 2014 6:49 PM
    • Moved by KareninstructorMVP Thursday, July 3, 2014 8:57 PM Moved from C#
    Thursday, July 3, 2014 6:48 PM

Answers

  • Hello Sahar,

    What color scheme are you talking about? Do you mean the Office theme shown on the image above?

    If so, the Word object model doesn't provide any property or method for this. All settings are stored in the windows registry:

    HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common
    where 14.0 is the Office version (corresponds to Office 2010), 15.0 for Office 2013.

    Look for the Theme key. Values are:

    Blue - 1.

    Silver - 2.

    Black - 3.

    • Marked as answer by _Sahar Friday, July 4, 2014 6:45 PM
    Friday, July 4, 2014 9:12 AM
  • I used the code below, Is is correct?

    const string OfficeCommonKey =
    @"HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common";
    const string OfficeThemeValueName = "Theme";
    const int ThemeBlue = 1;
    const int ThemeSilver = 2;
    const int ThemeBlack = 3;
    
    using (RegistryKey key = Registry.CurrentUser.OpenSubKey(OfficeCommonKey, false))
      {
          int theme = (int)key.GetValue(OfficeThemeValueName, 1);
    
          switch (theme)
              {
                 case ThemeBlue:
                    ...
                    break;
                 case ThemeSilver:
                    ...
                    break;
                 case ThemeBlack:
                    ...
                    break;
                 default:
                    ...
                    break;
               }
                  
    }

    • Marked as answer by _Sahar Friday, July 4, 2014 6:44 PM
    Friday, July 4, 2014 10:45 AM
  • The Word object model doesn't provide any property or method for this. I.e. there is no trivial way for getting the job done. As a workaround, you can implement the solution which involves some Windows API functions (described above).
    Friday, July 4, 2014 2:01 PM

All replies

  • Hello Sahar,

    What color scheme are you talking about? Do you mean the Office theme shown on the image above?

    If so, the Word object model doesn't provide any property or method for this. All settings are stored in the windows registry:

    HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common
    where 14.0 is the Office version (corresponds to Office 2010), 15.0 for Office 2013.

    Look for the Theme key. Values are:

    Blue - 1.

    Silver - 2.

    Black - 3.

    • Marked as answer by _Sahar Friday, July 4, 2014 6:45 PM
    Friday, July 4, 2014 9:12 AM
  • Hi,

    In the code above, I find you are using ThemeColorScheme.Colors Method.  However, the ThemeColorScheme.Colors method is used to get a color in the color scheme of a Microsoft Office theme. You cannot use the code above to set the color scheme.

    What's the meaning of "change the colorsheme of Microsoft Word"? Do you mean that you want to set the color scheme property or set the color of theme?

    If so, we have to know that color scheme of Word application and the theme color of the document are 2 different things.

    If you want to change the theme, you could use the method below.

    _Application.SetDefaultTheme Method


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, July 4, 2014 10:13 AM
    Moderator
  • I wannna change the blue area color. What should I do?

    Please help me!

    Friday, July 4, 2014 10:42 AM
  • I used the code below, Is is correct?

    const string OfficeCommonKey =
    @"HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common";
    const string OfficeThemeValueName = "Theme";
    const int ThemeBlue = 1;
    const int ThemeSilver = 2;
    const int ThemeBlack = 3;
    
    using (RegistryKey key = Registry.CurrentUser.OpenSubKey(OfficeCommonKey, false))
      {
          int theme = (int)key.GetValue(OfficeThemeValueName, 1);
    
          switch (theme)
              {
                 case ThemeBlue:
                    ...
                    break;
                 case ThemeSilver:
                    ...
                    break;
                 case ThemeBlack:
                    ...
                    break;
                 default:
                    ...
                    break;
               }
                  
    }

    • Marked as answer by _Sahar Friday, July 4, 2014 6:44 PM
    Friday, July 4, 2014 10:45 AM
  • Yes, it is. Do you get the currently selected color scheme?
    Friday, July 4, 2014 11:47 AM
  • As I already wrote, you need to set the appropriate value in the windows registry (see my previous reply) and send a Windows API message to the main window - WM_MSO_BROADCASTCHANGE or restart the host application to apply changes you made in the windows registry.  
    Friday, July 4, 2014 11:51 AM
  • Would you please tell me how I can switch betwean ThemeBlue and ThemeSilver with C# programming?
    Friday, July 4, 2014 12:10 PM
  • The Word object model doesn't provide any property or method for this. I.e. there is no trivial way for getting the job done. As a workaround, you can implement the solution which involves some Windows API functions (described above).
    Friday, July 4, 2014 2:01 PM
  • I use above, but Key got the null value, Why is it happened?
    Friday, July 4, 2014 6:01 PM
  • I'd recommend asking such questions in the Visual C# forum instead.

    The current forum is for Word (Office) specific questions.

    Friday, July 4, 2014 6:33 PM
  • Ok, Thanks
    Friday, July 4, 2014 6:40 PM