Excel comment pop-ups usually go to the right, but sometimes they go to the left. Moving the left-popping comment to another column can make it pop right, as can modifying the comment’s contents. What is Excel doing with the column and comment information to control the pop-up direction? Can I control the pop-up direction more directly? MS doesn’t document this that I can find. I am not asking for a Visual Basic way to control the comment pop-up location, since I already know how to do this. Thanks so much.
The comment boxes are stored as shaped within the comment within the cell.
This code will control the pop up direction in relation to the active cell it is stored inside of.
(assuming a comment in cell D8)
Sub MoveCommentLocation()
Dim x As Integer
Dim y As Integer
Dim bVisible As Boolean
With Range("D8")
' read position of the cell
x = .Left
y = .Top
' if comment is initially hidden, we need to unhide it to move it
bVisible = .Comment.Visible
If Not bVisible Then .Comment.Visible = True
With .Comment.Shape
' move comment relative to the cell
.Left = x - 30
.Top = y + 50
End With
If Not bVisible Then .Comment.Visible = False
End With
End Sub
Note:
You need to unhide the comment before moving it if it’s hidden. (code included above)
Additionally, Excel chooses the closest corner of the comment box to the top right of the cell to chose where to draw it’s arrow. If your comment boxes will vary in size/shape due to context and font I’d suggest placing them to the bottom right of the cell so that the location will always have it pointing to the top left.
Tags: excelexcel