我已更新到 Excel 2016,以下在 Excel 2011 中运行的代码会生成此错误。
Dim Commnt As Comment
For Each Commnt In Application.ActiveSheet.Comments ' Autosize all comment boxes on the sheet
Commnt.Shape.TextFrame.AutoSize = True
Next
在 Excel 2016 中自动调整所有工作表注释的任务是如何完成的?经过进一步研究,我尝试了以下但没有成功。
Dim Shp As Shape
For Each Shp In wks1.Shapes
With Shp.TextFrame2
.AutoSize = msoAutoSizeShapeToFitText
.WordWrap = msoTrue
End With
Next Shp
最佳答案
如 MSDN 中所述,Comment 的 TextFrame(和 TextFrame2)属性在 Excel 2016 中是只读的。
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/shape-textframe-property-excel
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/shape-textframe2-property-excel
使用 Excel 365 进行的快速测试表明,可以使用 Shape 对象本身的 Autosize 属性来自动调整注释大小。
Dim Commnt As Comment
For Each Commnt In Application.ActiveSheet.Comments ' Autosize all comment boxes on the sheet
Commnt.Shape.AutoSize = True
Next
但是,这似乎不适用于 Excel 2016。
关于excel - Excel 2016 for Mac 中的自动调整注释框大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51448123/