我正在尝试在Excel 2016中创建一个模块,该模块将扫描工作表并自动调整找到的任何注释。我当前的代码要求我每次运行时都调整Column Letter。我正在寻找一种方法来遍历循环中的列。我目前的代码列在下面,我提前感谢任何人,我可以获得任何帮助。我当前的工作表仅使用A到P列。
Sub cmtsize()
ActiveSheet.Unprotect pswd
Range("a7:I7").Select
lrow = Cells(Rows.Count, 1).End(xlUp).Row
For xrow = 7 To lrow
xcell = "c" & lrow
Range(xcell).Select
If ActiveCell.Comment Is Nothing Then
GoTo nxt
Else
With Range(xcell).Comment.Shape
.TextFrame.AutoSize = True
End With
nxt:
End If
Next xrow
ActiveSheet.Protect pswd
Range("A6").Select
MsgBox "Finished!"
End Sub
这将调整指定工作表上的所有注释。 [更新]包含密码保护工作表的选项。以及完成的Msgbox。
Sub test()
Call ResizeComments(Sheet1)
MsgBox ("Finished!")
End Sub
Private Sub ResizeComments(ByVal ws As Worksheet, Optional ByVal Pass As String = "")
If Pass <> "" Then ws.Unprotect Pass
Dim oComment As Comment
For Each oComment In ws.Comments
oComment.Shape.TextFrame.AutoSize = True
Next
If Pass <> "" Then ws.Protect Pass
End Sub