/ExcelDarkMode

Customisable dark mode for Excel cell backgrounds

Primary LanguageVBAMIT LicenseMIT

ExcelDarkMode

Customisable Dark Mode for Excel cell backgrounds.

VBA based but will work on non-macro workbooks if you save it to your Personal workbook (see below).

This works by replacing the colour definitions for styles already defined in the workbook (rather than creating new styles).

Don't forget to toggle a workbook back to light mode before you share it with uninitiated friends!

ExcelDarkMode

Setup

To set this up you'll need to copy some VBA code into a new macro. Follow the links below to the code, and to support articles on creating personal macros and calling them from your quick access bar:

  1. Copy the code from DarkMode.vba to a new module in your PERSONAL.XLSB, save.
  2. Run the macro ToggleDarkMode to switch between dark and light modes
  3. For ease of use, add the macro to your Quick Access bar

Since added DarkMode2.vba

Customisation

To change the dark mode colours, change the Hex colour code parameters in the DarkMode Function:

   Call UpdateStyleColors(styleName:="Normal", fillColorHex:="#2E3440", fontColorHex:="#FFFFFF", borderColorHex:="#454545")

To find the Hex codes for your favourite colours, use the font colour 'More Colors' picker (and copy the Hex code from the bottom):

image

To set dark mode for a new style, copy the Call UpdateStyleColors... line and provide the style name. Don't forget to add the style to the LightMode Function as well.

What if it doesn't work for all cells?

This approach only works for cell styles. Cells which have had font/fill colours applied in addition to the cell style will not be darkened, since the additional formatting overrides cell style formatting.

For dark mode to work for these cells, you need to re-apply a cell style to these cells. Beware that this will remove ALL additional formatting on the cell that isn't defined in a style.

There's a macro ResetStyles to assist removing additional formatting so you can apply styles properly to a pre-existing workbook. Use with caution. Either save a copy of the file or copy the formatting/sheet to a new workbook to save the original formatting until you're happy with your changes. In some cases you may be better off selecting individual regions, clearing formatting manually.

It may take a bit of time to undo formatting and replace with proper cell styles for a pre-existing Workbook but this is good practice and should hopefully be a one-off activity. Or just accept that not all cells will be darkened.

Font colour isn't lightened

If the cell background gets darkedned but the font colour doesn't change (ie dark text on dark background), it's most likely because the font colour has been changed for those cells. This is a variation of the case in the section above - to fix you'd need to reapply a style to these cells

Known issues

  • Formatting in addition to a cell style (see above)
  • Table styles get reset when switching back to light mode
  • Doesn't work for cells where the formatting is locked

Feedback welcome

To send feedback, head to the GitHub repository and create a new issue.

Copyright

Copyright (c) 2021 Stuart Bell

Licenced under the MIT licence