Comment box

Xx7

Board Regular
Joined
Jan 29, 2011
Messages
126
I would like to create a macro that inserts a comment to a cell that is Arial 12 and Blue Text. I would like to run the macro, an input box will pop-up, I will type the text, then the comment will show. Thx :)
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi
This should do the job for you.

Code:
Sub AddCommentPrompt()
  Dim strComment As Comment
  Dim myText As String
  
  myText = InputBox("Enter Here Comment", "Comments Please")
  
  Set strComment = ActiveCell.Comment
  If Not (strComment Is Nothing) Then
    ActiveCell.Comment.Delete
  End If
  Set strComment = ActiveCell.AddComment
  If (myText <> "") Then
    strComment.Text Text:=myText
  End If
  With strComment.Shape.TextFrame.Characters.Font
    .Name = "Arial"
    .Size = 12
    .Bold = False
    .ColorIndex = 5
  End With
End Sub

Thanks
 
Upvote 0
Works great Tigs!! :) is there any way change the default width of the comment? and can the height be adjusted to the amount of rows entered... so that there is no blank white space below?
 
Upvote 0
Xx7

I dont know of any default width options. But if you change the size of the comment box based on the area of the comment box currently, you can typically get it to fit in based on your defined width..
as shown below

Code:
    Dim intCommentWidth As Integer
    strComment.Shape.TextFrame.AutoSize = True
    With strComment
      intCommentWidth = 250
      If .Shape.Width > intCommentWidth Then
        .Shape.Height = ((.Shape.Width * .Shape.Height) / intCommentWidth) * 1.2
        .Shape.Width = intCommentWidth
        ActiveCell.Value = strComment.Shape.Height & " - " & strComment.Shape.Width
      End If
    End With

thanks
tigs
 
Upvote 0
Hmmm... if I right a long comment with that code, I will get something like this: "84.75 - 249.75" or "34.5 - 249.75" showing up in the cell :confused:

Code:
Sub CommentInsert()
  Dim strComment As Comment
  Dim myText As String
 
  
  myText = InputBox("Enter Here Comment", "Comments Please")
  
  Set strComment = ActiveCell.Comment
  If Not (strComment Is Nothing) Then
    ActiveCell.Comment.Delete
  End If
  
  Set strComment = ActiveCell.AddComment
  If (myText <> "") Then
    strComment.Text Text:=myText
  End If
  With strComment.Shape.TextFrame.Characters.Font
    .Name = "Arial"
    .Size = 10
    .Bold = False
    .ColorIndex = 5
  End With
  
 
    Dim intCommentWidth As Integer
    strComment.Shape.TextFrame.AutoSize = True
    With strComment
      intCommentWidth = 250
      If .Shape.Width > intCommentWidth Then
        .Shape.Height = ((.Shape.Width * .Shape.Height) / intCommentWidth) * 1.2
        .Shape.Width = intCommentWidth
        ActiveCell.Value = strComment.Shape.Height & " - " & strComment.Shape.Width
      End If
    End With

  
End Sub
 
Upvote 0
sorry take out this line
i was testing it to make sure it worked.

Code:
ActiveCell.Value = strComment.Shape.Height & " - " & strComment.Shape.Width

thanks
tigs
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top