gpt4 book ai didi

vba - 调整 Excel 注释大小以适合特定宽度的文本

转载 作者:行者123 更新时间:2023-12-02 01:58:39 28 4
gpt4 key购买 nike

我想让评论框恰好适合评论(底部没有多余的空间)。

我知道有 .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

mycellmyRng 是 Range 数据类型,lArea 是 Long。

现在,这种方法效果相对较好,但会在许多评论的底部留下额外的空间,因为自动调整大小的文本占用的区域与自动调整大小的评论框的区域不同。

有没有办法检查注释中的空格然后修剪它?或者我所拥有的就是最好的吗?

最佳答案

试试这个...测试注释已放置在单元格 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

关于vba - 调整 Excel 注释大小以适合特定宽度的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45515769/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com