'VBA via Matlab App Designer: Legend not visible when I set the width

I'm trying to fix the width of my legend in VBA, more specifically via MATLAB using its App Designer. This is the code I'm using:

Chart1.Legend.Width = 6;
Chart1.Legend.Left = Chart1.PlotArea.InsideLeft + Chart1.PlotArea.InsideWidth - Chart1.Legend.Width - 2 * Chart1.Legend.Format.Line.Weight;
Chart1.Legend.Top = Chart1.PlotArea.InsideTop;  

When I remove the line where I set the width, the legend is visible, but when I add it, it disappears. I also checked the legend width without this line and confirmed that it is 6, so I don't believe that is the issue. Any help would be greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source