Reputation: 117
Has anyone any idea how to use Excel.XlLegendPosition.xlLegendPositionCustom
to specifically position the legend of a chart? Currently, I'm using
chart.Legend.Position = Excel.XlLegendPosition.xlLegendPositionBottom;
which does exactly what one would expect. Right up until the time when you try and print the chart. THEN it places the legend pretty much where ever it wants -- which isn't where I need it to be.
I've checked the MSDN and every other site I could think of. The best Microsoft can come up with is as follows:
xlLegendPositionCustom: A custom position.
There are no examples that I could find that show how to use this.
Thanks for any help.
Upvotes: 1
Views: 2035
Reputation: 3
I don't think you can set it to xlLegendPositionCustom
, it's read-only, i.e. when you 'ask'(Debug.Print
ActiveChart.Legend.Position
), after setting ActiveChart.Legend.Left
/ActiveChart.Legend.Top
you get -4161
which is xlLegendPositionCustom
.
Upvotes: 0
Reputation: 117
Okay, it doesn't seem as if anyone has encountered this particular issue -- or needed to use the command. No worries, I appreciate folks taking the time to look at the question.
I did find a workaround that allows you to position the legend using points. It appears if you use the preset positioning options (like Excel.XlLegendPosition.xlLegendPositionBottom), Excel positions the legend based on whatever magic MS uses to figure these things out. Since I couldn't figure out how to use the Excel.XlLegendPosition.xlLegendPositionCustom, I played around with the other commands and found these:
chart.Legend.Left = 375;
chart.Legend.Top = 450;
Those commands will take an int (I used 374 and 450) and using them, you can force the position of the legend to anywhere on the chart.
Upvotes: 2