调整excel注释大小以适合具有特定宽度的文本

ano*_*ous 7 excel vba comments excel-vba

我想让评论框恰好符合评论(底部没有额外的空格).

我知道有,.AutoSize但我希望最大宽度为300.

这是我的代码,

For Each mycell In myRng.Cells
    If Not (mycell.Comment Is Nothing) Then
      With mycell.Comment.Shape
        .TextFrame.AutoSize = True
        If .width > 300 Then
          lArea = .width * .height
          .width = 300
          .height = (lArea / 300)
        End If
      End With
    End If
Next mycell
Run Code Online (Sandbox Code Playgroud)

mycell并且myRng是Range数据类型,lArea是Long.

现在,这种方法相对较好,但在多个注释的底部留下了额外的空间,因为AutoSized文本占用的区域与AutoSized注释框的区域不同.

有没有办法检查评论中的空白区域然后修剪它?或者是我最好的将是什么?

jso*_*ola 4

试试这个...测试注释已放置在单元格 E4 中

Range("e4").Comment.Shape.TextFrame通过放入“监视”窗口中发现

Sub testComment()

    With Range("e4").Comment.Shape

        .TextFrame.AutoSize = True

        lArea = .Width * .Height

        .Width = 300
        .Height = (lArea / .Width)       ' used .width so that it is less work to change final width

        .TextFrame.AutoMargins = False
        .TextFrame.MarginBottom = 0      ' margins need to be tweaked
        .TextFrame.MarginTop = 0
        .TextFrame.MarginLeft = 0
        .TextFrame.MarginRight = 0
    End With
End Sub
Run Code Online (Sandbox Code Playgroud)