试图在搜索中单步执行列

问题描述 投票:0回答:1

我正在尝试在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
vba excel-vba excel-2016
1个回答
3
投票

这将调整指定工作表上的所有注释。 [更新]包含密码保护工作表的选项。以及完成的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
© www.soinside.com 2019 - 2024. All rights reserved.