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.
Adds a border to a NamedRange control and sets the Color, LineStyle, and Weight properties for the new border.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
Syntax
'Declaration
Function BorderAround ( _
LineStyle As Object, _
Weight As XlBorderWeight, _
ColorIndex As XlColorIndex, _
Color As Object _
) As Object
Object BorderAround(
Object LineStyle,
XlBorderWeight Weight,
XlColorIndex ColorIndex,
Object Color
)
Parameters
- LineStyle
Type: System.Object
The line style for the border. Can be one of the following XlLineStyle values:
xlContinuous
xlDash
xlDashDot
xlDashDotDot
xlDot
xlDouble
xlSlantDashDot
xlLineStyleNone
- Weight
Type: Microsoft.Office.Interop.Excel.XlBorderWeight
The border weight. Can be one of the following XlBorderWeight constants:
xlHairline
xlMedium
xlThick
xlThin
- ColorIndex
Type: Microsoft.Office.Interop.Excel.XlColorIndex
The border color, as an index into the current color palette or as an XlColorIndex constant. Can be one of the following XlColorIndex constants:
xlColorIndexAutomatic
xlColorIndexNone
- Color
Type: System.Object
The border color, as an RGB value.
Return Value
Type: System.Object
Remarks
You must specify either ColorIndex or Color, but not both.
You can specify either LineStyle or Weight, but not both. If you do not specify either argument, Microsoft Office Excel uses the default line style and weight.
This method outlines the entire range without filling it in. To set the borders of all the cells, you must set the Color, LineStyle, and Weight properties for the Borders collection. To clear the border, you must set the LineStyle property to xlLineStyleNone for all the cells in the range.
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.
Examples
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 BorderAround method to draw a thick border around NamedRange1.
This example is for a document-level customization.
Private Sub SetRangeFormats()
Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
= Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
"namedRange1")
namedRange1.NoteText("This is a Formatting test", , )
namedRange1.Value2 = "Martha"
namedRange1.Font.Name = "Verdana"
namedRange1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
namedRange1.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
namedRange1.BorderAround(, Excel.XlBorderWeight.xlThick, _
Excel.XlColorIndex.xlColorIndexAutomatic, )
namedRange1.AutoFormat( _
Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1, _
True, False, True, False, True, True)
If MessageBox.Show("Clear the formatting and notes?", _
"Test", MessageBoxButtons.YesNo) = DialogResult.Yes Then
namedRange1.ClearFormats()
namedRange1.ClearNotes()
End If
End Sub
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();
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.