Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can apply named styles to regions in workbooks. Excel supplies a number of predefined styles.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Excel. For more information, see Features available by Office application and project type.
The Format Cells dialog box displays all the options you can use to format cells, and each of these options is available from your code. To display this dialog box in Excel, click Cells on the Format menu.
Create a new style and set its attributes.
Excel.Style style = Globals.ThisWorkbook.Styles.Add("NewStyle");
style.Font.Name = "Verdana";
style.Font.Size = 12;
style.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
style.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Gray);
style.Interior.Pattern = Excel.XlPattern.xlPatternSolid;
Create a NamedRange control, assign text to it, and then apply the new style. This code must be placed in a sheet class, not in the ThisWorkbook
class.
Apply the Normal style to the range. This code must be placed in a sheet class, not in the ThisWorkbook
class.
Create a new style and set its attributes.
Excel.Style style = this.Application.ActiveWorkbook.Styles.Add("NewStyle");
style.Font.Name = "Verdana";
style.Font.Size = 12;
style.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
style.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Gray);
style.Interior.Pattern = Excel.XlPattern.xlPatternSolid;
Create a Range, assign text to it, and then apply the new style.
Apply the Normal style to the range.
Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!