Microsoft Office Tutorials and References
In Depth Information
Selecting a Color in a UserForm
The GetAColor UserForm has another twist: It remembers the last color that was selected.
When the function ends, the three ScrollBar values are stored in the Windows Registry, using this
code ( APPNAME is a string defined in Module1 ):
SaveSetting APPNAME, “Colors”, “RedValue”, ScrollBarRed.Value
SaveSetting APPNAME, “Colors”, “BlueValue”, ScrollBarBlue.Value
SaveSetting APPNAME, “Colors”, “GreenValue”, ScrollBarGreen.Value
The UserForm_Initialize procedure retrieves these values and assigns them to the
scrollbars:
ScrollBarRed.Value = GetSetting(APPNAME, “Colors”, “RedValue”, 128)
ScrollBarGreen.Value = GetSetting(APPNAME, “Colors”, “GreenValue”, 128)
ScrollBarBlue.Value = GetSetting(APPNAME, “Colors”, “BlueValue”, 128)
The last argument for the GetSetting function is the default value, which is used if the Registry
key is not found. In this case, each color defaults to 128, which produces middle gray.
The SaveSetting and GetSetting functions always use this Registry key:
HKEY_CURRENT_USER\Software\VB and VBA Program Settings\
Figure 15-24 shows the Registry data, displayed with the Windows Regedit.exe program.
To learn more about how Excel uses colors, refer to Chapter 30.
Figure 15-24: The user’s ScrollBar values are stored in the Windows Registry and retrieved the next time
the GetAColor function is used.
 
Search JabSto ::




Custom Search