NamedRange.Offset Property (2007 System)

Gets a Range that is offset from the NamedRange control.

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

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property Offset As NamedRange._OffsetType
'Usage
Dim instance As NamedRange 
Dim value As NamedRange._OffsetType 

value = instance.Offset
[BrowsableAttribute(false)]
public NamedRange._OffsetType Offset { get; }
[BrowsableAttribute(false)]
public:
property NamedRange._OffsetType^ Offset {
    NamedRange._OffsetType^ get ();
}
public function get Offset () : NamedRange._OffsetType

Property Value

Type: Microsoft.Office.Tools.Excel.NamedRange._OffsetType
A Range that is offset from the NamedRange control.

Remarks

The Offset property is intended to be used with the following parameters.

Parameter

Description

RowOffset

The number of rows (positive, negative, or 0 (zero)) by which the range is to be offset. Positive values are offset downward, and negative values are offset upward. The default value is 0.

ColumnOffset

The number of columns (positive, negative, or 0 (zero)) by which the range is to be offset. Positive values are offset to the right, and negative values are offset to the left. The default value is 0.

If you attempt to use Offset without specifying any parameters, Offset will get a NamedRange._OffsetType object that is part of the Visual Studio Tools for Office infrastructure and is not intended to be used directly from your code.

Optional Parameters

For information on optional parameters, see The Variable missing and Optional Parameters in Office Solutions.

Examples

The following code example creates a NamedRange and then adds text to a cell offset from the NamedRange by three columns and three cells.

This version is for a document-level customization.

Private offsetRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub ActivateOffset()
    offsetRange = Me.Controls.AddNamedRange( _
        Me.Range("B1"), "offsetRange")

    Dim activateRange As Excel.Range = _
        CType(Me.offsetRange.Offset(3, 3), Excel.Range)
    offsetRange.Value2 = "Original range."
    activateRange.Value2 = "Offset range."
    activateRange.Select()
End Sub
Microsoft.Office.Tools.Excel.NamedRange offsetRange;
private void ActivateOffset()
{
    offsetRange = this.Controls.AddNamedRange(
         this.Range["B1", missing], "offsetRange");

    Excel.Range activateRange =
        (Excel.Range)this.offsetRange.Offset[3, 3];
    offsetRange.Value2 = "Original range.";
    activateRange.Value2 = "Offset range.";
    activateRange.Select();
}

This version is for an application-level add-in.

Private offsetRange As NamedRange

Private Sub ActivateOffset()
    Dim vstoWorksheet As Worksheet = CType( _
        Me.Application.ActiveWorkbook.Worksheets(1),  _
        Excel.Worksheet).GetVstoObject()
    offsetRange = vstoWorksheet.Controls.AddNamedRange( _
        vstoWorksheet.Range("B1"), "offsetRange")

    Dim activateRange As Excel.Range = _
        CType(offsetRange.Offset(3, 3), Excel.Range)
    offsetRange.Value2 = "Original range."
    activateRange.Value2 = "Offset range."
    activateRange.Select()
End Sub
NamedRange offsetRange;
private void ActivateOffset()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    offsetRange = vstoWorksheet.Controls.AddNamedRange(
         vstoWorksheet.Range["B1", missing], "offsetRange");

    Excel.Range activateRange =
        (Excel.Range)offsetRange.Offset[3, 3];
    offsetRange.Value2 = "Original range.";
    activateRange.Value2 = "Offset range.";
    activateRange.Select();
}

.NET Framework Security

See Also

Reference

NamedRange Class

NamedRange Members

Microsoft.Office.Tools.Excel Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.