Confusing VBA comment insertion behavior in Excel

后端 未结 2 1803
眼角桃花
眼角桃花 2021-01-29 03:42

I\'m going to rewrite this request. I see that I could be clearer.

From within the spreadsheet I highlight a cell where I want a standardized comment inserted. I use a k

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-29 03:53

    Properly indenting the code makes it more obvious that the entirety of it in Sub CommentAddLabor only runs if there is no comment in the selected cell.

    You want:

    Public Sub CommentAddLabor()
        If Ct Is Nothing Then
            ActiveCell.AddComment
        End If
        Set Ct = ActiveCell.Comment
        CommentFormat 'calls the sub above
        Ct.Text "Function: " & Chr(10) & "Envision: " & Chr(10) & "Activity: " & Chr(10) & "Material: " & Chr(10) & "Duration: " & Chr(10) & "Consider: "
    End Sub
    

提交回复
热议问题