AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 2,151
- Office Version
- 2019
- 2010
- Platform
- Windows
VBA Code:
Sub FormatComment(TheCell)
Dim cell As Range
Dim commentShape As Shape
Dim desiredWidth As Single
' Set your desired comment width (in points)
desiredWidth = 600
' Specify the cell containing the comment
Set cell = ActiveSheet.Range(TheCell)
' Check if the cell has a comment
If Not cell.Comment Is Nothing Then
' Access the comment's shape
Set commentShape = cell.Comment.Shape
' Set the comment's width
commentShape.Width = desiredWidth
' Ensure AutoSize is disabled to allow word wrap
commentShape.TextFrame.AutoSize = False
' Optional: Adjust the height to fit the text
commentShape.Height = commentShape.TextFrame.TextRange.BoundHeight + 10
Else
MsgBox "The specified cell does not contain a comment."
End If
End Sub
Wordrap and width are good but the line commentShape.Height = commentShape.TextFrame.TextRange.BoundHeight + 10
Causes error
Run-time error '438':
Object doesn't support this property or method
Using Excel 2016. Height is critical, can i resolve this anyhow?