In this Excel VBA UserForm Text Box Font Color Tutorial, you learn how to change an ActiveX Text Box's font color with Excel macros (when the ActiveX Text Box is in a UserForm).
This Excel VBA UserForm Text Box Font Color Tutorial:
- Applies to Text Boxes in a UserForm. These are the Text Boxes you insert (for example) through the Visual Basic Editor's (VBE's) Toolbox.
- Doesn't apply to the following:
- Basic Text Boxes in a worksheet.
- These are the Text Boxes you insert (for example) through the Text Box command in the Insert tab of the Excel Ribbon.
- If you want to learn how to change a Text Box's font color with Excel macros, I suggest you read my Excel VBA Text Box Font Color Tutorial. I link to this Tutorial in the Related Excel Macro and VBA Training Materials and Resources Section below.
- ActiveX Text Boxes in a worksheet.
- These are the Text Boxes you insert (for example) through the Insert dropdown in the Developer tab of the Ribbon.
- If you want to learn how to change an ActiveX Text Box's font color (when the ActiveX Text Box is in a worksheet) with Excel macros, I suggest you read my Excel VBA ActiveX Text Box Font Color Tutorial. I link to this Tutorial in the Related Excel Macro and VBA Training Materials and Resources Section below.
- Basic Text Boxes in a worksheet.
This Excel VBA UserForm Text Box Font Color Tutorial is accompanied by an Excel workbook with the data and VBA code I use when describing the step-by-step process below. Get this example workbook (for free) by clicking the button below.
The VBA code in the Excel workbook that accompanies this Excel VBA UserForm Text Box Font Color Tutorial is (always) stored in the Visual Basic Editor (VBE). If you don't know how to work with the VBE, I suggest you read my Visual Basic Editor (VBE) Tutorial. I link to this Tutorial in the Related Excel Macro and VBA Training Materials and Resources Section below.
Table of Contents
Related Excel Macro and VBA Training Materials and Resources
The following Excel Macro and VBA Tutorials may help you better understand and implement the contents below.
- Tutorials about general macro and VBA constructs and structures:
- Tutorials for Beginners:
- Excel Macros: Click here to open.
- Excel VBA: Click here to open.
- Enable macros in Excel: Click here to open.
- Work with the Visual Basic Editor (VBE): Click here to open.
- Create Sub procedures: Click here to open.
- Refer to objects: Click here to open.
- Work with:
- Properties: Click here to open.
- Data types: Click here to open.
- Functions: Click here to open.
- Events: Click here to open.
- The Select Case statement: Click here to open.
- Tutorials for Beginners:
- Tutorials with practical VBA applications and macro examples:
- Work with the Value property: Click here to open.
- Work with font characteristics: Click here to open.
- Create UserForms: Click here to open.
This Excel VBA UserForm Text Box Font Color Tutorial is part of a more comprehensive series of Excel VBA Font Color Tutorials.
- Excel VBA Font Color Index in 2 Easy Steps: Click here to open.
- Excel VBA Font Color RGB in 2 Easy Steps: Click here to open.
- Excel VBA Font Color HEX in 5 Easy Steps: Click here to open.
- Excel VBA Change Font Color Based on Cell Value in 4 Easy Steps: Click here to open.
- Excel VBA Change Font Color for Part of Text in 8 Easy Steps: Click here to open.
- Excel VBA Text Box Font Color in 2 Easy Steps: Click here to open.
- Excel VBA ActiveX Text Box Font Color in 2 Easy Steps: Click here to open.
- Excel VBA Chart Data Label Font Color in 4 Easy Steps: Click here to open.
- Excel VBA ActiveX Label Font Color in 2 Easy Steps: Click here to open.
- Excel VBA UserForm Label Font Color in 2 Easy Steps: Click here to open.
You can find more Excel and VBA Tutorials in the organized Tutorials Archive: Click here to visit the Archives.
If you want to learn how to automate Excel (and save time) by working with macros and VBA, you may be interested in the following Premium Excel Macro and VBA Training Materials:
- Premium Courses at the Power Spreadsheets Academy: Click here to open.
- Books at the Power Spreadsheets Library: Click here to open.
- VBA Cheat Sheets: Click here to open.
If you want to save time when working with macros and VBA, you may be interested in AutoMacro: Click here to learn more about AutoMacro (affiliate link). AutoMacro is an add-in for VBA that installs directly into the VBE. Depending on the version, AutoMacro comes loaded with:
- Code generators.
- An extensive code library.
- The ability to create your own code library.
- Advanced coding tools.
If you need consulting services, you may want to consider working with ExcelRescue. ExcelRescue is my usual suggestion for people who (like you) may need help with Excel tasks/projects: Click here to visit ExcelRescue (affiliate link).
The VBA UserForm Text Box Font Color Snippet Template/Structure
The following is the VBA UserForm Text Box font color snippet template/structure I explain (step-by-step) in the Sections below.
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
UserFormObjectReference.TextBoxControlCodeName.ForeColor = NewForeColorValue
The Example Before VBA UserForm Text Box Font Color
This Excel VBA UserForm Text Box Font Color Tutorial is accompanied by an Excel workbook with the data and VBA code I use when describing the step-by-step process below. Get this example workbook (for free) by clicking the button below.
The VBA code in the Excel workbook that accompanies this Excel VBA UserForm Text Box Font Color Tutorial is (always) stored in the Visual Basic Editor (VBE). If you don't know how to work with the VBE, I suggest you read my Visual Basic Editor (VBE) Tutorial. I link to this Tutorial in the Related Excel Macro and VBA Training Materials and Resources Section above.
The example workbook has a UserForm with a single TextBox control.
This is the UserForm Text Box the VBA UserForm Text Box font color example macro I create (by following the step-by-step process below) works with. In other words: This is the UserForm Text Box where the example macro (when executed) sets the font color.
Step 1: Refer to UserForm Text Box
Refer to the UserForm Text Box whose font color you want to set.
In other words: Create a VBA expression that returns an ActiveX TextBox control (object) representing the UserForm Text Box whose font color you want to set.
Consider doing the following when referring to the UserForm Text Box you work with:
- Store the procedure setting the UserForm Text Box font color inside the applicable UserForm class module.
- Use:
- The Me keyword to refer to the applicable UserForm.
- The Text Box's codename to refer to the applicable TextBox control (object) inside the applicable UserForm.
- Find (and change) the Text Box's codename ((Name) property) in the applicable Properties Window.
The basic expression structure/template to refer to the UserForm Text Box is as follows:
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
UserFormObjectReference.TextBoxControlCodeName
Step 1 Example
I:
- Store the example procedure (setting the UserForm Text Box font color) inside the applicable UserForm class module.
- Work with a With… End With block. The statements inside the With… End With block work with the UserForm Text Box.
- Refer to the Text Box codenamed “UserFormTextBoxFontColor” inside the UserForm.
- Work with the following VBA constructs to obtain an ActiveX TextBox control (object) representing this UserForm Text Box:
- The Me keyword: Me.
- The ActiveX Text Box's codename: UserFormTextBoxFontColor.
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
With Me.UserFormTextBoxFontColor
'Statements
End With
Step 2: Set the Value of the ForeColor Property
Do the following to set the applicable ActiveX Text Box's font color with the ForeColor property:
(1) Start with the ActiveX TextBox control (object) reference you created in step #1:
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
UserFormObjectReference.TextBoxControlCodeName
(2) Refer to the ForeColor property.
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
UserFormObjectReference.TextBoxControlCodeName.ForeColor
(3) Set the value of the ForeColor property.
The ForeColor property specifies the UserForm Text Box's font color as a value of the Long data type representing the applicable red, green, and blue components.
- Consider working with the RGB function to set the value of the of the ForeColor property by specifying the applicable red, green, and blue components.
- If you don't know how to work with the RGB function, I suggest you read my Excel VBA Font Color RGB Tutorial I link to in the Related Excel Macro and VBA Training Materials and Resources Section above.
You can (also) consider setting the ForeColor property to:
- Any of VBA's color constants:
- vbBlack.
- vbRed.
- vbGreen.
- vbYellow.
- vbBlue.
- vbMagenta.
- vbCyan.
- vbWhite.
- Any of VBA's system color constants:
- vbScrollBars: Scroll bar color.
- vbDesktop: Desktop color.
- vbActiveTitleBar: Color of the active window's title bar.
- vbInactiveTitleBar: Color of an inactive window's title bar.
- vbMenuBar: Menu background color.
- vbWindowBackground: Window background color.
- vbWindowFrame: Window frame color.
- vbMenuText: Color text in menus.
- vbWindowText: Color text in windows.
- vbTitleBarText: Color text in caption, size box, and scroll arrow.
- vbActiveBorder: Active window's border color.
- vbInactiveBorder: Inactive window's border color.
- vbApplicationWorkspace: Background color of multiple document interface applications.
- vbHighlight: Background color of items selected in a control.
- vbHighlightText: Text color of items selected in a control.
- vbButtonFace: Shading color on the face of command buttons.
- vbButtonShadow: Shading color on the edge of command buttons.
- vbGrayText: Disabled (greyed out) text.
- vbButtonText: Push button text color.
- vbInactiveCaptionText: Text color in inactive caption.
- vb3DHighlight: Highlight color for 3-D display elements (Button Highlight).
- vb3DDKShadow: Darkest shadow color for 3-D display elements (Button Dark Shadow).
- vb3DLight: Second lightest 3-D color (after vb3DHighlight; Button Light Shadow).
- vbInfoText: Tooltip text color.
- vbInfoBackground: Tooltip background color.
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
UserFormObjectReference.TextBoxControlCodeName.ForeColor = NewForeColorValue
Step 2 Example
I do the following to set the value of the ForeColor property:
(1) Work with an event handler procedure triggered by the Change event of the applicable TextBox control (object). The Change event occurs when the Value property of the TextBox control (object) changes.
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
Private Sub UserFormTextBoxFontColor_Change()
With Me.UserFormTextBoxFontColor
'Statements
End With
End Sub
(2) Work with the If… Then… Else statement to do the following:
- Test whether the text in the Text Box's edit region is “Excel VBA UserForm Text Box Font Color”.
- Specify the value of the ForeColor property:
- One way (if the tested condition is met); or
- Another way (if the tested condition isn't met).
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
Private Sub UserFormTextBoxFontColor_Change()
With Me.UserFormTextBoxFontColor
If .Value = "Excel VBA UserForm Text Box Font Color" Then
'Statements
Else
'Statements
End If
End With
End Sub
If the text in the Text Box's edit region is “Excel VBA UserForm Text Box Font Color”, I use the RGB function to set the value of the ForeColor property (ForeColor = RGB(0, 128, 55)). I specify the Red, Green, and Blue arguments of the RGB function as follows:
- Red: 0.
- Green: 128.
- Blue: 55.
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
Private Sub UserFormTextBoxFontColor_Change()
With Me.UserFormTextBoxFontColor
If .Value = "Excel VBA UserForm Text Box Font Color" Then
.ForeColor = RGB(0, 128, 55)
Else
'Statements
End If
End With
End Sub
If the text in the Text Box's edit region isn't “Excel VBA UserForm Text Box Font Color”, I set the value of the ForeColor property to VBA's vbBlack color constant (ForeColor = vbBlack).
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
Private Sub UserFormTextBoxFontColor_Change()
With Me.UserFormTextBoxFontColor
If .Value = "Excel VBA UserForm Text Box Font Color" Then
.ForeColor = RGB(0, 128, 55)
Else
.ForeColor = vbBlack
End If
End With
End Sub
The full VBA UserForm Text Box font color example macro is as follows:
Private Sub UserFormTextBoxFontColor_Change()
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/userform-textbox-font-color/
'Step 1: Refer to the UserFormTextBoxFontColor Text Box in this UserForm
With Me.UserFormTextBoxFontColor
'Do the following:
'(1) Test whether the UserForm Text Box contains "Excel VBA UserForm Text Box Font Color"
'(2) Set the value of the ForeColor property depending on whether (or not) the UserForm Text Box contains "Excel VBA UserForm Text Box Font Color"
If .Value = "Excel VBA UserForm Text Box Font Color" Then
'Step 2 (option 1): Use the RGB function to set the value of the ForeColor property. Specify the red, green, and blue components of the color as follows:
'Red: 0
'Green: 128
'Blue: 55
.ForeColor = RGB(0, 128, 55)
Else
'Step 2 (option 2): Set the value of the ForeColor property to VBA's vbBlack color constant
.ForeColor = vbBlack
End If
End With
End Sub
The following GIF illustrates the effects of executing the VBA UserForm Text Box font color example macro (when the Change event of the TextBox control occurs).
Download the VBA Userform Text Box Font Color Example Workbook
This Excel VBA UserForm Text Box Font Color Tutorial is accompanied by an Excel workbook with the data and VBA code I use when describing the step-by-step process above. Get this example workbook (for free) by clicking the button below.
The VBA code in the Excel workbook that accompanies this Excel VBA UserForm Text Box Font Color Tutorial is (always) stored in the Visual Basic Editor (VBE). If you don't know how to work with the VBE, I suggest you read my Visual Basic Editor (VBE) Tutorial. I link to this Tutorial in the Related Excel Macro and VBA Training Materials and Resources Section above.
Related Excel Macro and VBA Training Materials and Resources
The following Excel Macro and VBA Tutorials may help you better understand and implement the contents above.
- Tutorials about general macro and VBA constructs and structures:
- Tutorials for Beginners:
- Excel Macros: Click here to open.
- Excel VBA: Click here to open.
- Enable macros in Excel: Click here to open.
- Work with the Visual Basic Editor (VBE): Click here to open.
- Create Sub procedures: Click here to open.
- Refer to objects: Click here to open.
- Work with:
- Properties: Click here to open.
- Data types: Click here to open.
- Functions: Click here to open.
- Events: Click here to open.
- The Select Case statement: Click here to open.
- Tutorials for Beginners:
- Tutorials with practical VBA applications and macro examples:
- Work with the Value property: Click here to open.
- Work with font characteristics: Click here to open.
- Create UserForms: Click here to open.
This Excel VBA UserForm Text Box Font Color Tutorial is part of a more comprehensive series of Excel VBA Font Color Tutorials.
- Excel VBA Font Color Index in 2 Easy Steps: Click here to open.
- Excel VBA Font Color RGB in 2 Easy Steps: Click here to open.
- Excel VBA Font Color HEX in 5 Easy Steps: Click here to open.
- Excel VBA Change Font Color Based on Cell Value in 4 Easy Steps: Click here to open.
- Excel VBA Change Font Color for Part of Text in 8 Easy Steps: Click here to open.
- Excel VBA Text Box Font Color in 2 Easy Steps: Click here to open.
- Excel VBA ActiveX Text Box Font Color in 2 Easy Steps: Click here to open.
- Excel VBA Chart Data Label Font Color in 4 Easy Steps: Click here to open.
- Excel VBA ActiveX Label Font Color in 2 Easy Steps: Click here to open.
- Excel VBA UserForm Label Font Color in 2 Easy Steps: Click here to open.
You can find more Excel and VBA Tutorials in the organized Tutorials Archive: Click here to visit the Archives.
If you want to learn how to automate Excel (and save time) by working with macros and VBA, you may be interested in the following Premium Excel Macro and VBA Training Materials:
- Premium Courses at the Power Spreadsheets Academy: Click here to open.
- Books at the Power Spreadsheets Library: Click here to open.
- VBA Cheat Sheets: Click here to open.
If you want to save time when working with macros and VBA, you may be interested in AutoMacro: Click here to learn more about AutoMacro (affiliate link). AutoMacro is an add-in for VBA that installs directly into the VBE. Depending on the version, AutoMacro comes loaded with:
- Code generators.
- An extensive code library.
- The ability to create your own code library.
- Advanced coding tools.
If you need consulting services, you may want to consider working with ExcelRescue. ExcelRescue is my usual suggestion for people who (like you) may need help with Excel tasks/projects: Click here to visit ExcelRescue (affiliate link).