다음을 통해 공유


NamedRange.MergeArea Property

Definition

Gets a Range that represents the merged range containing the NamedRange control.

public:
 property Microsoft::Office::Interop::Excel::Range ^ MergeArea { Microsoft::Office::Interop::Excel::Range ^ get(); };
public Microsoft.Office.Interop.Excel.Range MergeArea { get; }
member this.MergeArea : Microsoft.Office.Interop.Excel.Range
Public ReadOnly Property MergeArea As Range

Property Value

A Range that represents the merged range containing the NamedRange control. If the NamedRange control is not in a merged range, this property returns a Range that represents the NamedRange control.

Examples

The following code example displays the value of the MergeArea and MergeCells properties of a single-cell NamedRange before and after using the Merge method to merge a multiple-cell NamedRange that contains the single-cell NamedRange.

This example is for a document-level customization.

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

    Microsoft.Office.Tools.Excel.NamedRange namedRange2 =
        this.Controls.AddNamedRange(this.Range["A1"],
        "namedRange2");

    string beforeMergeAddress = namedRange2.MergeArea.get_Address(
        Excel.XlReferenceStyle.xlA1);

    MessageBox.Show("Before merging, the MergeArea property is '" +
        beforeMergeAddress + "' and the MergeCells property is " +
        " '" + namedRange2.MergeCells.ToString() + "'.");

    namedRange1.Select();
    namedRange1.Merge(false);

    string afterMergeAddress = namedRange2.MergeArea.get_Address(
        Excel.XlReferenceStyle.xlA1);

    MessageBox.Show("After merging, the MergeArea property is '" +
        afterMergeAddress + "' and the MergeCells property is " +
        " '" + namedRange2.MergeCells.ToString() + "'.");
}
Private Sub MergeRange()
    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
        "namedRange1")

    Dim namedRange2 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1"), "namedRange2")

    Dim beforeMergeAddress As String = _
        namedRange2.MergeArea.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    MessageBox.Show("Before merging, the MergeArea property is '" & _
        beforeMergeAddress & "' and the MergeCells property is " & _
        " '" & namedRange2.MergeCells.ToString() & "'.")

    namedRange1.Select()
    namedRange1.Merge(False)

    Dim afterMergeAddress As String = _
        namedRange2.MergeArea.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    MessageBox.Show("After merging, the MergeArea property is '" & _
        afterMergeAddress & "' and the MergeCells property is " & _
        " '" & namedRange2.MergeCells.ToString() & "'.")
End Sub

Remarks

The MergeArea property only works on a single-cell range.

Applies to