ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Format a Comment created by a Macro (https://www.excelbanter.com/excel-discussion-misc-queries/42926-format-comment-created-macro.html)

Ken G.

Format a Comment created by a Macro
 
Thanks to Ken Johnson's help I have a Comment box which appears only if a
condition is met. This comment has been created by a small macro. It seems
that because the comment box is not a standard Excel comment, but has been
created by the macro, any attempt to format the text box (dimensions,
alignment, no shadow etc) fails. It looks like the formatting has to be
included in the macro, but so far I haven't been able to do this. Can anyone
help?

mudraker


Ken

can you post the code that creates the Comment box


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=400311


[email protected]

mudraker,
If you are addressing Ken Johnson here is the code I posted for Ken.G.
If you're addressing Ken.G then please ignore this reply.

Just as a demo, if the value in cell A1 of the active sheet changes to
become greater than 10 then Cell B1 has the comment "A1 is greater than

10" added.
The code must be pasted into the ThisWorkbook module. If you don't
want all sheets affected then paste the code into the WorkSheet_Change

Sub of the sheet you want affected.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If ActiveSheet.Cells(1, 1).Value 10 Then
With ActiveSheet.Cells(1, 2)
On Error Resume Next 'if no comment to delete then error is
ignored
.Comment.Delete 'remove old comment
On Error GoTo 0
.AddComment
.Comment.Visible =3D True 'change to False if you only want to
see the comment
'when the cursor is positioned over the

commented cell
.Comment.Text Text:=3D"A1 is greater than 10"
.Comment.Shape.TextFrame.AutoS=ADize =3D True 'comment frame size
will suit any size comment
End With
Else: On Error Resume Next
ActiveSheet.Cells(1, 2).Comment.Delete 'delete old comment because A1
is not 10=20
On Error GoTo 0=20
End If=20
End Sub=20

Ken Johnson


Ken G.

Don't ignore Ken Johnson's post. That's the code I used to create the
conditional comment. I've since tried recording a macro while creating and
formatting a comment, then copied that code into my macro but it keeps coming
up with errors. I don't know enough about vbasic I'm afraid.

"mudraker" wrote:


Ken

can you post the code that creates the Comment box


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=400311




All times are GMT +1. The time now is 06:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com