VBA: adjusting size of comments

JaredSorensen

Board Regular
Joined
Aug 23, 2007
Messages
160
I've recorded the steps of what I want a macro to do. Unfortunately, I can't seem to size a comment correctly. I must be missing some step, or perhaps the macro doesn't "play back" correctly.

Any tips for what I need to do to get the comment to be appropriately sized to display the text is an aesthetic format? I've run into this issue before and I don't know how to solve it. Thanks.

Jared

code:
Code:
Sub Add_comment_and_adjust_size()
    Range("a1").Select
    Range("a1").AddComment
    Range("a1").Comment.Visible = False
    Range("a1").Comment.Text Text:="Jared Sorensen:" & Chr(10) & ""
    'Selection.ShapeRange.ScaleWidth 2.56, msoFalse, msoScaleFromTopLeft
    'Selection.ShapeRange.ScaleHeight 2.1, msoFalse, msoScaleFromTopLeft
    'Range("a1").Comment.Shape.Select True
    Range("a1").Comment.Text Text:= _
        "Jared Sorensen:" & Chr(10) & "Four regressions were run to quantify the relationship between Euclidean distance (as the crow flies) and PC Miler distance (actual road distance)." & Chr(10) & "" & Chr(10) & "Overall, the correlation was 99% fo"
    Range("a1").Comment.Text Text:= _
        "r y = 1.236x + 6.74." & Chr(10) & "" & Chr(10) & "For distances <15 miles, y = 1.099x + 2.02 (R2 =.83)" & Chr(10) & "For distances <25 miles, y = 1.262x + 2.10 (R2 =.80)" & Chr(10) & "For distances <50 miles, y = 1.337x + 3.05 (R2 =.91)" & Chr(10) & "" _
        , Start:=200
    'Selection.ShapeRange.ScaleWidth 1.05, msoFalse, msoScaleFromTopLeft
    'Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I'm not sure exactly what you are after. You can set:
Code:
Comment.Shape.Textframe.Autosize = True
if that helps?
 
Upvote 0
Rorya,

Thanks, that did the trick. The only limitation that approach has is that it autosizes the width as per the longest sentence. Since my first sentence was verbose, it resulted in too wide of a comment.

To get around that, I inserted additional carriage returns Chr(10) and now it works fine. Thanks for your help.

Jared

Code:
Sub Macro9()
    Range("c23").Select
    Range("c23").AddComment
    Range("c23").Comment.Visible = False
    Range("c23").Comment.Text Text:="Jared Sorensen:" & Chr(10) & ""
    'Selection.ShapeRange.ScaleWidth 2.56, msoFalse, msoScaleFromTopLeft
    'Selection.ShapeRange.ScaleHeight 2.1, msoFalse, msoScaleFromTopLeft
    'Range("R7").Comment.Shape.Select True
    Range("c23").Comment.Text Text:= _
        "Jared Sorensen:" & Chr(10) & "Four regressions were run to quantify the relationship " & Chr(10) & "between Euclidean distance (as the crow flies) and" & Chr(10) & "PC Miler distance (actual road distance)." & Chr(10) & "" & Chr(10) & "Overall, the correlation was 99% fo"
    Range("c23").Comment.Text Text:= _
        "r y = 1.236x + 6.74." & Chr(10) & "" & Chr(10) & "For distances <15 miles, y = 1.099x + 2.02 (R2 =.83)" & Chr(10) & "For distances <25 miles, y = 1.262x + 2.10 (R2 =.80)" & Chr(10) & "For distances <50 miles, y = 1.337x + 3.05 (R2 =.91)" & Chr(10) & "" _
        , Start:=200
    'Selection.ShapeRange.ScaleWidth 1.05, msoFalse, msoScaleFromTopLeft
    'Selection.ShapeRange.ScaleWidth 1.03, msoFalse, msoScaleFromTopLeft
    Range("c23").Comment.Shape.TextFrame.AutoSize = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

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