I have a textbox (VBA shape type 17) embedded in a chart embedded in a worksheet that is protected:
Sheet11.ChartObjects(1).Chart.Shapes(1)
I want to assign calculated text to the textbox using VBA.
With the worksheet protected, I can successfully set the text in Excel 2016 using this (and several other variations of syntax):
Sheet11.ChartObjects(1).Chart.Shapes(1).TextFrame2.Textrange.Text = "Textbox Text"
The same code works in Excel 2007 only if the worksheet is unprotected. With the sheet protected, runtime error 1004 "Unable to set the Text Property" is generated, even if the parent chart Locked property is False.
In both 2007 and 2016 I cannot set the Locked property of the embedded textbox. This property is not available in the UI, nor can it be assigned in VBA. The Shapes(1).Locked property always returns True, and remains True even if I assign the property to False.
Unprotecting the worksheet first, or assigning the text to the contents of a cell both work, but are less desirable solutions (for various reasons). The inability to set the text when protected seems like a bug in Excel 2007.
Is my VBA code somehow wrong?
Sheet11.ChartObjects(1).Chart.Shapes(1)
I want to assign calculated text to the textbox using VBA.
With the worksheet protected, I can successfully set the text in Excel 2016 using this (and several other variations of syntax):
Sheet11.ChartObjects(1).Chart.Shapes(1).TextFrame2.Textrange.Text = "Textbox Text"
The same code works in Excel 2007 only if the worksheet is unprotected. With the sheet protected, runtime error 1004 "Unable to set the Text Property" is generated, even if the parent chart Locked property is False.
In both 2007 and 2016 I cannot set the Locked property of the embedded textbox. This property is not available in the UI, nor can it be assigned in VBA. The Shapes(1).Locked property always returns True, and remains True even if I assign the property to False.
Unprotecting the worksheet first, or assigning the text to the contents of a cell both work, but are less desirable solutions (for various reasons). The inability to set the text when protected seems like a bug in Excel 2007.
Is my VBA code somehow wrong?