SOLVED

VBA to Autosize an Excel note is not working for me on MAC/365 works on Windows/Excel v10

%3CLINGO-SUB%20id%3D%22lingo-sub-2068929%22%20slang%3D%22en-US%22%3EVBA%20to%20Autosize%20an%20Excel%20note%20is%20not%20working%20for%20me%20on%20MAC%2F365%20works%20on%20Windows%2FExcel%20v10%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2068929%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20tried%20reinstalling%20Excel%20on%20my%20MAC%20to%20no%20avail.%20This%20is%20the%20VBA%20and%20it%20is%20the%20'xComment.Shape.TextFrame.AutoSize%20%3D%20True'%20statement%20it%20objects%20to.%20I%20have%20wasted%20a%20whole%20afternoon%20on%20this%20and%20really%20need%20some%20help.%20Mark%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3ESub%20FitComments()%3CBR%20%2F%3EDim%20xComment%20As%20Comment%3CBR%20%2F%3EFor%20Each%20xComment%20In%20Application.ActiveSheet.Comments%3CBR%20%2F%3ExComment.Shape.TextFrame.AutoSize%20%3D%20True%3CBR%20%2F%3ENext%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2068929%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2081926%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20to%20Autosize%20an%20Excel%20note%20is%20not%20working%20for%20me%20on%20MAC%2F365%20works%20on%20Windows%2FExcel%20v10%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2081926%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F932305%22%20target%3D%22_blank%22%3E%40Mark_Smith_007%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMark%2C%3C%2FP%3E%3CP%3ESpent%20a%20long%20time%20looking%20at%20this%2C%20gave%20up%20a%20couple%20of%20times%20as%20being%20undoable.%20It%20appears%20that%20on%20a%20Mac%20autosize%20does%20not%20work.%20I%20looked%20at%20various%20macros%20other%20people%20had%20done%20and%20ended%20up%20butchering%20one%20to%20work%20with%20comments.%20Even%20then%20there%20is%20still%20some%20guess%20work%20involved.%20In%20a%20nut%20shell%20the%20Mac%20copies%20the%20comments%20text%2C%20places%20it%20into%20a%20cell%20on%20a%20temporary%20sheet%2C%20sizes%20the%20cell%20with%20to%20the%20same%20width%20as%20the%20comment%2C%20the%20calculates%20how%20many%20lines%20of%20text%20there%20are%20then%20multiplies%20that%20by%20the%20text%20size%20in%20pixels%20to%20get%20the%20height%20of%20the%20comment.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENot%20100%25%20accurate%20but%20nearly%20gets%20it%20right.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERich%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2083313%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20to%20Autosize%20an%20Excel%20note%20is%20not%20working%20for%20me%20on%20MAC%2F365%20works%20on%20Windows%2FExcel%20v10%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2083313%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F259521%22%20target%3D%22_blank%22%3E%40Rich99%3C%2FA%3EHi%20Rich%2C%20thanks%20for%20this%20you%20have%20got%20me%20out%20of%20a%20hole.%20I%20needed%20to%20resolve%20this%20one%20way%20or%20another%20for%20next%20Monday%20so%20I%20am%20very%20happy.%20I%20will%20experiment%20with%20a%20bigger%20data%20set%20and%20see%20how%20I%20get%20on.%20Thanks%20again%2C%20Mark%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I have tried reinstalling Excel on my MAC to no avail. This is the VBA and it is the 'xComment.Shape.TextFrame.AutoSize = True' statement it objects to. I have wasted a whole afternoon on this and really need some help. Mark

Sub FitComments()
Dim xComment As Comment
For Each xComment In Application.ActiveSheet.Comments
xComment.Shape.TextFrame.AutoSize = True
Next

End Sub

2 Replies
Best Response confirmed by Mark_Smith_007 (New Contributor)
Solution

@Mark_Smith_007 

 

Mark,

Spent a long time looking at this, gave up a couple of times as being undoable. It appears that on a Mac autosize does not work. I looked at various macros other people had done and ended up butchering one to work with comments. Even then there is still some guess work involved. In a nut shell the Mac copies the comments text, places it into a cell on a temporary sheet, sizes the cell with to the same width as the comment, the calculates how many lines of text there are then multiplies that by the text size in pixels to get the height of the comment.

 

Not 100% accurate but nearly gets it right.

 

Rich

@Rich99Hi Rich, thanks for this you have got me out of a hole. I needed to resolve this one way or another for next Monday so I am very happy. I will experiment with a bigger data set and see how I get on. Thanks again, Mark