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
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
Whats happening is this:
Note
. Its value persists.AddServiceNote
, Note Is Nothing
is TRUE, so the If Then
code runsIf
code, Note
is Set
to somethingAddServiceNote
, Note Is Nothing
is FALSE, so the If Then
code does not runFormatNotes
executes a For
loop, setting Note
on each iterationFor
loop, Note
is left as Nothing
(that's a side effect of the For
)FormatNotes
, AddServiceNote
will work again (once)The fix is simple
Dim Note As ...
inside AddServiceNote
(there is nothing about the code posted that required Note
to be Module Scoped)OrganizeElements
's signature toPublic Sub OrganizeElements(Note As Comment)
OrganizeElements
to pass Note
as a parameter:OrganizeElements Note
Public Sub AddServiceNote()
Dim Note As Comment
If ActiveCell.Comment Is Nothing Then
Set Note = ActiveCell.AddComment
Note.Text Text:="Function: "
OrganizeElements Note
End If
End Sub
Public Sub FormatNotes()
Dim Note As Comment
For Each Note In ActiveSheet.Comments
OrganizeElements Note
Next
End Sub
Public Sub OrganizeElements(Note As Comment)
Note.Shape.TextFrame.AutoSize = True
'and a long list of other attributes
End Sub