Excel VBA: Preserve Custom Colors in the ChooseColor Dialog
Question details
The user needs to retain custom colors selected in the Windows ChooseColor API dialog for later openings during the Excel session.
- Product
- Microsoft Excel VBA and the Windows ChooseColor API
- Device & OS
- not provided
- Scenario
- A VBA procedure opens the ChooseColor dialog and passes a custom-color array through the lpCustColors parameter.
- Observed behavior
- Custom colors are not available the next time the dialog opens because the array or variable loses its values when the procedure ends.
Locate the ChooseColor API declaration and identify the array or variable supplied to lpCustColors. Confirm whether the colors only need to persist during the current Excel session or across separate launches of Excel.
Declare the lpCustColors array at module or global scope
Use this solution when custom colors need to remain available each time the dialog opens during the current Excel session.
A procedure-level array is recreated or goes out of scope after the procedure finishes. Declaring the array in the declarations section of a standard module keeps it in memory, allowing ChooseColor to update and reuse the custom-color slots.
This preserves the colors while Excel remains open. To retain them after Excel closes, save the array values to a file, registry entry, or worksheet and load them before opening the dialog.
In Excel, press Alt+F11, then select the workbook project in the Project Explorer and choose Insert > Module to open a standard module.
At the top of the module, outside every Sub or Function, declare the array used by lpCustColors, for example: Private mCustomColors(0 To 15) As Long.
In the procedure that opens the picker, pass the first element of the module-level array to the lpCustColors parameter, such as mCustomColors(0), using the argument format required by your ChooseColor API declaration.
Run the macro with F5, choose custom colors, close the dialog, and open it again without closing Excel. The saved custom colors should appear in the picker.
Use WPS Office as a lightweight alternative for compatible spreadsheet workflows
WPS Office is a free, lightweight Microsoft Office alternative with a familiar spreadsheet interface and strong compatibility with Excel XLS and XLSX files. It can help you migrate everyday workbook tasks, although Excel-specific VBA and Windows ChooseColor API code may require redesign or a compatible macro environment.
- 1. Install WPS Office: Download and install WPS Office, then open WPS Spreadsheets from the application launcher.
- 2. Open the Excel workbook: Choose Open from the WPS Office home screen and select the XLS or XLSX workbook you want to review or migrate.
- 3. Check macro-dependent features: Review any Excel VBA procedures, Windows API declarations, and ChooseColor integrations separately because Office-specific macro behavior may not transfer directly.

Frequently Asked Questions
Why do custom ChooseColor colors disappear after the VBA procedure ends?
The lpCustColors array is likely declared inside the procedure, so it loses its values when the procedure exits. Declare the array in the declarations section of a standard module or at global scope instead.
Where should the lpCustColors array be declared in Excel VBA?
Open the VBA editor with Alt+F11, insert or select a standard module, and declare the array above all Sub and Function procedures. For example, use Private mCustomColors(0 To 15) As Long.
Will a module-level array preserve custom colors after Excel closes?
No. Module-level scope preserves the values only while the Excel application is running. To keep them between sessions, save the color values to a worksheet, file, or registry entry and reload them before calling ChooseColor.
How do I confirm that the ChooseColor dialog is using the persistent array?
Run the macro, select one or more custom colors, close the picker, and open it again during the same Excel session. If the colors remain visible, the lpCustColors parameter is using the module-level array correctly.




