调整excel注释的大小以适应具有特定宽度的文本
我想要评论框适合正确的意见(底部没有额外的空间)。
我知道有.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
mycell
和myRng
是Range数据types, lArea
是Long。
现在,这个工作比较好,但在许多注释的底部留下了额外的空间,因为AutoSized文本占用的区域与AutoSized注释框的区域不同。
有没有办法检查评论里面的空白,然后修剪它? 或者,我有最好的将是什么?
试试这个…testing评论已经放在单元格E4中
在Watch窗口中放置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