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
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
My code works on Windows Excel. I don't have Mac Office so don't know why it doesn't like that line, but try changing:

Function Word_Wrap(text As String, maxLineLength As Integer) As String

to:

Function Word_Wrap(ByVal text As String, ByVal maxLineLength As Integer) As String

If still no good, is there any Help for the Function keyword built in to Mac Excel VBA?
 
Upvote 0
That didnt work for the Mac, but an earlier code did, and your code did work for the PC so that is great. Thanks to everyone who helped me out.

Much appreciated :)
 
Upvote 0
EDIT:

nevermind - looks like we made it :) good news.
 
Upvote 0
Mac VBA does not support Split (or Join or Replace or a dictionary object) which is why the function WordWrap doesn't work on a Mac.
One workaround would be writting a function, mySplit, and having WordWrap call mySplit instead
Code:
Function mySplit(InputString As String, Optional Delimiter As String) As Variant
    Dim outRRay() As String
    Dim point As Long, cutPoint As Long
    
    If Delimiter = vbNullString Then Delimiter = " "
    If Application.OperatingSystem Like "*Mac*" Then
        Rem Split emulator for Macs
        InputString = InputString & Delimiter
        ReDim outRRay(0 To ((Len(InputString) / 2) + 1))
        point = 0
        outRRay(0) = vbNullString
        
        Do Until Len(InputString) = 0
            cutPoint = InStr(InputString, Delimiter)
            outRRay(point) = Trim(Left(InputString, cutPoint - 1))
            InputString = Mid(InputString, cutPoint + Len(Delimiter))
            If outRRay(point) <> vbNullString Then point = point + 1
        Loop
        
        If point = 0 Then point = 1
        ReDim Preserve outRRay(0 To point - 1)
        mySplit = outRRay
    Else
        Rem no emulator for Windows
        mySplit = Split(InputString, Delimiter)
    End If
End Function
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,395
Members
449,446
Latest member
CodeCybear

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