Chart.Location(XlChartLocation, Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Moves the Chart control to a new location.
public Microsoft.Office.Interop.Excel.Chart Location (Microsoft.Office.Interop.Excel.XlChartLocation Where, object Name);
abstract member Location : Microsoft.Office.Interop.Excel.XlChartLocation * obj -> Microsoft.Office.Interop.Excel.Chart
Public Function Location (Where As XlChartLocation, Optional Name As Object) As Chart
Parameters
- Where
- XlChartLocation
XlChartLocation. Where to move the chart.
- Name
- Object
The name of the sheet where the chart is embedded if Where
is xlLocationAsObject or the name of the new sheet if Where
is xlLocationAsNewSheet.
Returns
Examples
The following code example creates a Chart and then uses the Location method to move the chart to a new sheet named "Sales".
private void MoveChartToNewSheet()
{
this.Range["A1", "A5"].Value2 = 22;
this.Range["B1", "B5"].Value2 = 55;
Microsoft.Office.Tools.Excel.Chart chart1 =
this.Controls.AddChart(this.Range["D2", "H12"],
"chart1");
chart1.SetSourceData(this.Range["A1", "B5"],
Excel.XlRowCol.xlColumns);
chart1.ChartType = Excel.XlChartType.xl3DColumn;
chart1.Location(Excel.XlChartLocation.xlLocationAsNewSheet,
"Sales");
}
Private Sub MoveChartToNewSheet()
Me.Range("A1", "A5").Value2 = 22
Me.Range("B1", "B5").Value2 = 55
Dim Chart1 As Microsoft.Office.Tools.Excel.Chart = _
Me.Controls.AddChart(Me.Range("D2", "H12"), "Chart1")
Chart1.SetSourceData(Me.Range("A1", "B5"), Excel.XlRowCol.xlColumns)
Chart1.ChartType = Excel.XlChartType.xl3DColumn
Chart1.Location(Excel.XlChartLocation.xlLocationAsNewSheet, "Sales")
End Sub
Remarks
If you want to move a chart to another position on a sheet, use the Top property and Left property of the ChartArea. You can get the ChartArea object of the Chart by using the ChartArea property.
Optional Parameters
For information on optional parameters, see Optional Parameters in Office Solutions.