当在Excel (2016)中添加单元格注释时,注释框的大小是众所周知的次优,需要手动调整。我定义了这个宏(用我从这里获得的VBA代码)来自动调整当鼠标悬停在单元格上方时出现的单元格注释的大小:
Sub FitComments()
Dim xComment As Comment
For Each xComment In Application.ActiveSheet.Comments
xComment.Shape.TextFrame.AutoSize = True
Next
End Sub
但是,我希望这个宏能够:
然而,我对VBA并没有真正的了解。有人能指出我必须对代码做哪些修改吗?谢谢!
发布于 2019-02-05 20:22:00
Sub FitComments()
Dim Rng As Range
Dim Cell As Range
Set Rng = Selection
For Each Cell In Rng
If Not Cell.Comment Is Nothing Then
Cell.Comment.Shape.TextFrame.AutoSize = True
End If
Next
End Sub
Excel 2016在我目前的位置无法测试上面的内容,否则在发布之前我会这样做的。我正在运行Office 365,它会按照您的描述自动调整大小。对多个版本进行了测试,直到宏没有出错。
此代码背后的概念是在每个单元格的基础上将自动大小应用于选择范围内的注释。
我将宏应用于控件+(选择字母)键盘的激活,以便快速访问。
在逐行代码的基础上,它通过测试选择的预期步骤数运行。
发布于 2019-03-19 07:56:55
Sub Resize_All_Comments()
Dim xComment As Comment
Dim KHeight As Long
Dim KWidth As Long
On Error Resume Next
KHeight = Application.InputBox("Add text", "Height", "500", Type:=2)
KWidth = Application.InputBox("Add text", "Width", "500", Type:=2)
For Each xComment In Application.Select.Comment
xComment.Shape.Width = KWidth
xComment.Shape.Height = KHeight
Next
MsgBox "Done"
End Sub
使用此选项,您可以根据需要调整大小,请注意,它将调整当前工作表中所有注释的大小。
希望它能帮到别人
https://stackoverflow.com/questions/54539574
复制相似问题