VBA在Mac的MS Excel 2011中自动调整注释框的大小在Mac的MS Excel 2016中不起作用

时间:2018-07-20 18:02:51

标签: excel vba excel-vba excel-vba-mac

由于购买了运行macOS 10.12.6(High Sierra)的新MacBook Pro,因此我已更新到MS Excel 2016,以下在MS Excel 2011中运行良好的代码在MS Excel 2016和I中产生此错误无法解决该问题!

Run-time error '1004' Method 'TextFrame' of object 'Shape' failed

Dim Commnt As Comment

For Each Commnt In Application.ActiveSheet.Comments ' Autosize all comment boxes on the sheet
Commnt.Shape.TextFrame.AutoSize = True
Next

您能告诉我如何完成MS 2016中所有工作表注释的自动化任务吗?

经过进一步的研究,我还尝试了以下方法,但未成功影响注释框。

Dim Shp As Shape
For Each Shp In wks1.Shapes
    With Shp.TextFrame2
        .AutoSize = msoAutoSizeShapeToFitText
        .WordWrap = msoTrue
    End With
Next Shp

1 个答案:

答案 0 :(得分:0)

如MSDN中所述,注释的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中似乎无效。