Collapse the table of content
Expand the table of content
Expand Minimize

NamedRange.AutoFormat Method

Automatically formats the NamedRange control, using a predefined format.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Object AutoFormat(
	XlRangeAutoFormat Format,
	Object Number,
	Object Font,
	Object Alignment,
	Object Border,
	Object Pattern,
	Object Width
)

Parameters

Format
Type: Microsoft.Office.Interop.Excel.XlRangeAutoFormat
Can be one of the following XlRangeAutoFormat constants:
xlRangeAutoFormat3DEffects1
xlRangeAutoFormat3DEffects2
xlRangeAutoFormatAccounting1
xlRangeAutoFormatAccounting2
xlRangeAutoFormatAccounting3
xlRangeAutoFormatAccounting4
xlRangeAutoFormatClassic1
xlRangeAutoFormatClassic2
xlRangeAutoFormatClassic3
xlRangeAutoFormatClassicPivotTable
xlRangeAutoFormatColor1
xlRangeAutoFormatColor2
xlRangeAutoFormatColor3
xlRangeAutoFormatList1
xlRangeAutoFormatList2
xlRangeAutoFormatList3
xlRangeAutoFormatLocalFormat1
xlRangeAutoFormatLocalFormat2
xlRangeAutoFormatLocalFormat3
xlRangeAutoFormatLocalFormat4
xlRangeAutoFormatNone
xlRangeAutoFormatPTNone
xlRangeAutoFormatReport1
xlRangeAutoFormatReport10
xlRangeAutoFormatReport2
xlRangeAutoFormatReport3
xlRangeAutoFormatReport4
xlRangeAutoFormatReport5
xlRangeAutoFormatReport6
xlRangeAutoFormatReport7
xlRangeAutoFormatReport8
xlRangeAutoFormatReport9
xlRangeAutoFormatSimple
xlRangeAutoFormatTable1
xlRangeAutoFormatTable10
xlRangeAutoFormatTable2
xlRangeAutoFormatTable3
xlRangeAutoFormatTable4
xlRangeAutoFormatTable5
xlRangeAutoFormatTable6
xlRangeAutoFormatTable7
xlRangeAutoFormatTable8
xlRangeAutoFormatTable9
The default constant is xlRangeAutoFormatClassic1.
Some of these constants might not be available to you, depending on the language support (U.S. English, for example) that you selected or installed.
Number
Type: System.Object
true to include number formats in the AutoFormat. The default value is true.
Font
Type: System.Object
true to include font formats in the AutoFormat. The default value is true.
Alignment
Type: System.Object
true to include alignment in the AutoFormat. The default value is true.
Border
Type: System.Object
true to include border formats in the AutoFormat. The default value is true.
Pattern
Type: System.Object
true to include pattern formats in the AutoFormat. The default value is true.
Width
Type: System.Object
true to include column width and row height in the AutoFormat. The default value is true.

Return Value

Type: System.Object

If the range is a single cell, this method also formats the active region surrounding the cell.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example demonstrates how to set a variety of formatting and display characteristics of a NamedRange control named NamedRange1. In particular, this example uses the AutoFormat method to format NamedRange1 using the xlRangeAutoFormat3DEffects1 format.

This example is for a document-level customization.


private void SetRangeFormats()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    namedRange1.NoteText("This is a Formatting test", missing, missing);
    namedRange1.Value2 = "Martha";
    namedRange1.Font.Name = "Verdana";
    namedRange1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
    namedRange1.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
    namedRange1.BorderAround(missing, Excel.XlBorderWeight.xlThick,
        Excel.XlColorIndex.xlColorIndexAutomatic, missing);
    namedRange1.AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1,
        true, false, true, false, true, true);

    if (MessageBox.Show("Clear the formatting and notes?", "Test",
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        namedRange1.ClearFormats();
        namedRange1.ClearNotes();
    }
}


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft