In this Excel VBA Text Box Font Color Tutorial, you learn how to change a Text Box's font color with Excel macros.
The Excel VBA Text Box Font Color Tutorial:
- Applies to 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.
- Doesn't apply to the following:
- 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 Excel Ribbon.
- If you want to learn how to change an ActiveX Text Box's font color 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.
- Text Boxes in a UserForm.
- ActiveX Text Boxes in a worksheet.
This Excel VBA 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 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), including sheets (click here to open).
- Work with:
- Properties: Click here to open.
- Data types: Click here to open.
- Functions: Click here to open.
- Tutorials for Beginners:
- Tutorials with practical VBA applications and macro examples:
- Activate workbook: Click here to open.
- Work with font characteristics: Click here to open.
This Excel VBA 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 ActiveX Text Box Font Color in 2 Easy Steps: Click here to open.
- Excel VBA UserForm 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 Text Box Font Color Snippet Template/Structure
The following is the VBA 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/vba-textbox-font-color/
WorkbookObjectReference.WorksheetObjectReference.Shapes(NameOrIndexNumber).TextFrame2.TextRange.Font.Fill.ForeColor.RgbOrSchemeColor = NewRgbOrSchemeColorValue
The Example Before VBA Text Box Font Color
This Excel VBA 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 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 worksheet has a Text Box with the text “Set this Text Box's Font Color”.
This is the Text Box the VBA Text Box font color example macro I create (by following the step-by-step process below) works with. In other words: This is the Text Box where the example macro (when executed) sets the font color.
The following image displays the example worksheet before I execute the VBA Text Box font color example macro.
Step 1: Refer to Text Box
Refer to the Text Box whose font color you want to set.
In other words: Create a VBA expression that returns a Shape object representing the Text Box whose font color you want to set.
Consider explicitly including the following references to create a fully qualified object reference returning a Worksheet object (representing the worksheet where the Text Box is):
- A reference to the applicable workbook. The following VBA constructs (among others) may return a Workbook object:
- The Application.ThisWorkbook property.
- The Application.Workbooks and Workbooks.Item properties.
- The Application.ActiveWorkbook property.
- A reference to the applicable worksheet. The following VBA constructs (among others) may return a Worksheet object:
- The Workbook.Sheets and Sheets.Item properties.
- The Workbook.Worksheets and Worksheets.Item properties.
- The Application.ActiveSheet property.
As a general rule, use the following 2 properties to refer to the applicable Text Box (Shape object) inside the applicable worksheet:
- Worksheet.Shapes.
- Shapes.Item.
If you choose to specify the Shape's object (representing the Text Box) name (instead of using its index number) when working with the Shapes.Item property, consider whether you must wrap the string in double quotes (Shapes(“Name”)).
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/vba-textbox-font-color/
WorkbookObjectReference.WorksheetObjectReference.Shapes(NameOrIndexNumber)
Step 1 Example
I:
- Refer to the Text Box named “TextBoxFont” in the “Excel VBA Text Box Font Color” worksheet inside the workbook where the procedure is stored.
- Work with the following VBA constructs to obtain a Shape object representing this Text Box:
- The Application.ThisWorkbook property: ThisWorkbook.
- The Workbook.Worksheets and Worksheets.Item properties: Worksheets(“Excel VBA Text Box Font Color”).
- The Worksheet.Shapes and Shapes.Item properties: Shapes(“TextBoxFont”).
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/vba-textbox-font-color/
ThisWorkbook.Worksheets("Excel VBA Text Box Font Color").Shapes("TextBoxFont")
Step 2: Set the Value of the ColorFormat.RGB or ColorFormat.SchemeColor Property
Use either of the following 2 properties to set the color of the applicable Text Box's font:
- ColorFormat.RGB.
- ColorFormat.SchemeColor.
Do the following to set the value of the ColorFormat.RGB or ColorFormat.SchemeColor property:
(1) Start with the Shape object reference you created in step #1:
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/vba-textbox-font-color/
WorkbookObjectReference.WorksheetObjectReference.Shapes(NameOrIndexNumber)
(2) Refer to the following:
- The Shape.TextFrame2 property.
- The TextFrame2.TextRange property.
- The TextRange2.Font property.
- The Font2.Fill property.
- The FillFormat.ForeColor property.
- The ColorFormat.RGB property or the ColorFormat.SchemeColor property (as applicable).
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/vba-textbox-font-color/
WorkbookObjectReference.WorksheetObjectReference.Shapes(NameOrIndexNumber).TextFrame2.TextRange.Font.Fill.ForeColor.RgbOrSchemeColor
(3) Set the value of the ColorFormat.RGB property or ColorFormat.SchemeColor property.
- The ColorFormat.RGB property specifies the 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 ColorFormat.RGB 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 the 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 ColorFormat.RGB property to any of VBA's color constants:
- vbBlack.
- vbRed.
- vbGreen.
- vbYellow.
- vbBlue.
- vbMagenta.
- vbCyan.
- vbWhite.
- The ColorFormat.SchemeColor property specifies the font color as an index value into the current color palette.
- If you don't know how to work with the VBA Color Palette, I suggest you read the Excel VBA Font Color Index Tutorial I link to in the Related Excel Macro and VBA Training Materials and Resources Section above.
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/vba-textbox-font-color/
WorkbookObjectReference.WorksheetObjectReference.Shapes(NameOrIndexNumber).TextFrame2.TextRange.Font.Fill.ForeColor.RgbOrSchemeColor = NewRgbOrSchemeColorValue
Step 2 Example
I:
- Work with the ColorFormat.RGB property.
- Use the RGB function to set the value of the ColorFormat.RGB property (ForeColor.RGB = 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/vba-textbox-font-color/
ThisWorkbook.Worksheets("Excel VBA Text Box Font Color").Shapes("TextBoxFont").TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 128, 55)
The full VBA Text Box font color example macro is as follows:
Sub TextBoxFontColor()
'Source: https://powerspreadsheets.com/
'More information: https://powerspreadsheets.com/vba-textbox-font-color/
'Do the following:
'Step 1: Refer to color of the text inside the "TextBoxFont" Text Box in the "Excel VBA Text Box Font Color" worksheet in this workbook
'Step 2: Use the RGB function to set the value of the ColorFormat.RGB property. Specify the red, green, and blue components of the color as follows:
'Red: 0
'Green: 128
'Blue: 55
ThisWorkbook.Worksheets("Excel VBA Text Box Font Color").Shapes("TextBoxFont").TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 128, 55)
End Sub
The following GIF illustrates the effects of using the VBA Text Box font color example macro.
Download the VBA Text Box Font Color Example Workbook
This Excel VBA 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 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), including sheets (click here to open).
- Work with:
- Properties: Click here to open.
- Data types: Click here to open.
- Functions: Click here to open.
- Tutorials for Beginners:
- Tutorials with practical VBA applications and macro examples:
- Activate workbook: Click here to open.
- Work with font characteristics: Click here to open.
This Excel VBA 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 ActiveX Text Box Font Color in 2 Easy Steps: Click here to open.
- Excel VBA UserForm 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).