Excel 用于自动调整单元格注释大小的VBA代码
在Excel(2016)中添加单元格注释时,注释框的大小众所周知是次优的,需要手动调整。我定义了这个宏(使用我从中获得的VBA代码)来自动调整鼠标悬停在单元格上方时显示的单元格注释的大小:Excel 用于自动调整单元格注释大小的VBA代码,excel,Excel,在Excel(2016)中添加单元格注释时,注释框的大小众所周知是次优的,需要手动调整。我定义了这个宏(使用我从中获得的VBA代码)来自动调整鼠标悬停在单元格上方时显示的单元格注释的大小: Sub FitComments() Dim xComment As Comment For Each xComment In Application.ActiveSheet.Comments xComment.Shape.TextFrame.AutoSize = True Next End Sub
Sub FitComments()
Dim xComment As Comment
For Each xComment In Application.ActiveSheet.Comments
xComment.Shape.TextFrame.AutoSize = True
Next
End Sub
但是,我希望此宏改为:
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,它会按照您的描述自动调整大小。测试了多个版本,直到宏没有出错
此代码背后的概念是在每个单元格的基础上对所选内容中的注释应用autosize
我将宏应用于Control+(选择字母)键盘激活,以便快速访问
逐行进入代码中,它完成了测试选择的预期步骤数
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
使用此选项可以根据需要调整大小,请注意,它将调整当前工作表中所有注释的大小
希望它能帮助别人这个宏叫什么名字?非常感谢!但是,注释框仍然是一个长长的单行,而不是一个更适合文本的矩形。谢谢,我会试试的!