The Problem (Q-score 5, ranked #232nd of 303 in the Excel VBA archive)
The scenario as originally posted in 2010
I am trying to generate an Excel chart from C#. Chart is generated just find but it allways appears at the center of the screen. How can I set the position of the chart?
Thanks.
My code looks like this:
Microsoft.Office.Interop.Excel._Workbook ebook = (Microsoft.Office.Interop.Excel._Workbook)etablo.Workbooks.Add(true);
Microsoft.Office.Interop.Excel._Worksheet esheet = (Microsoft.Office.Interop.Excel._Worksheet)ebook.ActiveSheet;
_Chart grafik1 = (Chart)ebook.Charts.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
/* Add Data From Cells here */
/* Then */
grafik1.Location(XlChartLocation.xlLocationAsObject, esheet.Name);
Why community consensus is tight on this one
Across 303 Excel VBA entries in the archive, the accepted answer here holds niche answer (below median) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — niche answer (below median) (+7)
6-line Excel VBA pattern (copy-ready)
after you generate a chart, you can handle chart as a shape object:
for example:
esheet.Shapes.Item("Chart 1").Top = 100;
esheet.Shapes.Item("Chart 1").Left = 250;
// or you can handle shape by index - indexes start from 1 so esheet.Shapes.Item(1).Top
i think, you would like to set position right the relevating cells, for example:
esheet.Shapes.Item("Chart 1").Top = (float)(double)esheet.get_Range("A5","A6").Top;
so …i hope this will help 🙂
Luboss
When to Use It — vintage (14+ years old, pre-2013)
Ranked #232nd in its category — specialized fit
This pattern sits in the 98% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Excel VBA archive for a higher-consensus alternative.
What changed between 2010 and 2026
The answer is 16 years old. The Excel VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.