calling excel genius - cell comment autosize??

darro

Board Regular
Joined
Mar 10, 2009
Messages
208
I have the code below, and it works perfectly on my Mac. But... on my PC it does not.

The cell comment does not resize horizontally when I enter text. So if I enter a long comment I get a comment box that extends far to the right to fit the contents in. Vertically it is fine, nothing cut off and no extra space.

Any ideas why this would be? Any ideas how I can force the text to wrap in the cell comment box?

Thanks in advance for your help. Code is below:

Code:
Sub AddCom()
Const USERNAME As String = "Greer:"
Dim strCommentName As String
Dim cmnt As String
Dim NoMore As Boolean
Dim Pos As Long
    
    cmnt = InputBox("Please enter a comment")
    strCommentName = cmnt & vbLf & Now
    On Error GoTo 0

    With activeCell
    
        If .Comment Is Nothing Then
        
            strCommentName = USERNAME & Chr(10) & strCommentName
        Else
    
            strCommentName = .Comment.Text & Chr(10) & vbLf & USERNAME & Chr(10) & strCommentName
            .Comment.Delete
        End If
     
        With .AddComment(strCommentName)
        
            .Visible = False
            .Shape.AutoShapeType = msoShapeRoundedRectangle
            
            Pos = 0
            Do
            
                Pos = InStr(Pos + 1, strCommentName, USERNAME)
                If Pos > 0 Then
                
                    With .Shape.TextFrame
                    
                        With .Characters(Pos, Len(USERNAME)).Font
                        
                            .Bold = True
                            .Italic = True
                            .ColorIndex = 3
                        End With
                    End With
                End If
            Loop Until Pos = 0
    
        End With
        
        .Comment.Shape.TextFrame.AutoSize = True
        .Comment.Visible = False
    End With
     
End Sub
 
I tried changing chr(10) to chr(13) on the PC but had no effect on the width of the cell comment. It did place a small square character at the start of the comment text though.

Surely there must be a way for this to be made to work. Thanks for your suggestion Mike, any more :)
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I'm on a Mac, so I can't test if it works on PC.
I do know using vbCR (chr(13)) in place of vbLf (chr(10)) has fixed other line wrapping differences between Mac and PC.
 
Upvote 0
Nope, I have changed all chr(10) and vbLf to chr(13) and nothing changed but for the small square icon at start.
 
Upvote 0
Darn. That square is Excels way of saying that it can't print the character as requested.
So, it sounds like vbLf is the one to use.
Perhaps adding this loop (after adjusting the constant to your taste) will work.
Code:
Const maxLineLength As Long = 20

cmnt = InputBox("Please enter a comment")

    For i = maxLineLength To Len(cmnt) Step maxLineLength + 1
        cmnt = Left(cmnt, i) & vbLf & Mid(cmnt, i + 1)
    Next

strCommentName = cmnt & vbLf & Now
 
Upvote 0
thats the closest so far Mike, cheers, it does now limit the width of the box but it has also returned the text a few lines below the user name, any idea how to fix that, thanks for your help, I was beginning to lose hope
 
Upvote 0
also it sets the Now on the same last line of text, I'd prefer it if it was on the very last line below the text
 
Upvote 0
fixed the Now problem, but not the extra lines of space, also, this will cut off any text after the limit, any way to stop that happening in the middle of a word? so only if its a space?
 
Upvote 0
its ok, wasn't your code, I had an extra vbLf in there, so now if it can be arranged so it only limits and then returns the text if the 20th character is a space or nearest space after 20 then this will be perfect and you will officially be a genius
 
Upvote 0

Forum statistics

Threads
1,214,863
Messages
6,121,978
Members
449,058
Latest member
oculus

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