Vba To Autosize Comment Box In Ms Excel 2011 For Mac

суббота 07 мартаadmin
I'm experiencing a strange problem when trying to autosize comments. I'm running a For/Next loop where I place data according to certain criteria in a row of cells, then add a comment (or update an existing comment if one is already there). For some reason I keep getting a 'Run-time error '1004': application-defined or object-defined error every time my code gets to the autosize line.

VBA to autosize comment box in MS Excel 2011 for Mac not working in MS Excel 2016 for Mac. Ask Question Asked 1 year, 4 months ago. Active 1 year, 4 months ago. Viewed 371 times 2. Due to the purchase of a new MacBook Pro running macOS 10.12.6 (High Sierra), I've updated to MS Excel 2016 and the following code which worked well in MS Excel 2011. I'm experiencing a strange problem when trying to autosize comments. I'm running a For/Next loop where I place data according to certain criteria in a row of cells, then add a comment (or update an existing comment if one is already there).

I've looked everywhere on the web and can't seem to find any information relating to this kind of error associated with comment autosizing. I would be extremely grateful for any suggestions from the experts here.
The relevant section of my code is as follows:
If Not Sheet12.Cells(TempRow, TempCol).Offset(0, ContractLength).Comment Is Nothing Then
TempCom = Sheet12.Cells(TempRow, TempCol).Offset(0, ContractLength).Comment.Text
Sheet12.Cells(TempRow, TempCol).Offset(0, ContractLength).ClearComments
TempStdName = Sheet10.Cells(FillRow, Sheet10.Range('Student_Name').Column)
Sheet12.Cells(TempRow, TempCol).AddComment.Text TempStdName & Chr(10) & TempCom
Sheet12.Cells(TempRow, TempCol).Comment.Shape.TextFrame.AutoSize = True
'Supposed to autosize the comment box - here is the where the problem is, the 1004 error is thrown at this line
Else
TempStdName = Sheet10.Cells(FillRow, Sheet10.Range('Student_Name').Column)
Sheet12.Cells(TempRow, TempCol).AddComment TempStdName
Sheet12.Cells(TempRow, TempCol).Comment.Shape.TextFrame.AutoSize = True
'Supposed to autosize comment box - here is where the problem is again, the 1004 error is thrown at this line
End If
This is the first time I am submitting something to the forum, so please excuse me if for some reason I am doing anything to violate forum protocol. I did read the rules carefully but may have missed something, and if so I apologize in advance. Please let me know if that is the case and I will try to make any corrections right away to this post to make it compliant.
Thanks very much,
Peter Winn

How do I get a macro to resize a comment box?

Thanks


You can get the code by using the macro recorder.


Hi Ben

Run this:

Sub ResizeComment()
'Written by OzGrid Business Applications
'www.ozgrid.com

Dim CBox As Comment
Set CBox = Range('F10').Comment

With CBox
.Text Text:='OzGrid Business Applications:'
.Shape.ScaleWidth 1.49, msoFalse, msoScaleFromBottomRight
.Shape.ScaleHeight 1.24, msoFalse, msoScaleFromBottomRight
End With

Vba to autosize comment box in ms excel 2011 for mac pro

Set CBox = Nothing
End Sub


OzGrid Business Applications

Ben if you want to resize ALL comment boxs
in an activesheet OR All sheets then this routine
may help you. Rsizing is @ 25% change as required.
Or scale down.

Sub ChangeSize_Comments_SSh()
Dim cCell As Range
Dim sComment As Comment
Dim allComments As Range
Dim Sh As Worksheet
Dim Ans As Integer
Dim All As Boolean

Ans = MsgBox('Activesheet (Yes) or ALL sheets (No)', vbYesNoCancel)
If Ans = 2 Then Exit Sub

All = IIf(Ans = 7, True, False)

If Not All Then Set Sh = ActiveSheet: GoTo skipSh

It marks the user Documents and Pictures folders as protected by default, and you can add more folders. Avast cleanup pro for mac torrent.

For Each Sh In ActiveWorkbook.Sheets

skipSh:
On Error Resume Next
Set allComments = Sh.Range('A1').SpecialCells(xlCellTypeComments)
If allComments Is Nothing And Not All Then MsgBox 'No comments in ' & ActiveSheet.Name: GoTo Ex
'Leave On Error Resume next ON to take care of Loop not set error
'when doing active sheet only.

For Each cCell In allComments
With cCell.Comment
'lock aspect to get even increase in size
.Shape.LockAspectRatio = True
'increase by 25% change as required
.Shape.Height = .Shape.Height * 1.25
End With
Next cCell
Next Sh

Ex:
Set allComments = Nothing
Set Sh = Nothing

End Sub

Ivan

Off topic..more or less


Ivan -- I introduced you to a site for Dutch accountants & accountancy students. See:

http://www.accountingweb.nl/cgi-bin/item.cgi?id=43565&d=101&h=0&f=0&dateformat=%o%20%B%20%Y

And also a long overdue: Welcome back.

Aladin

Re: Off topic..more or less

Aladin
Great..many thanks for that. I see that you
have been busy on this site. Keep up the great
work. I'm sure you have helped a lot of people.

regards

Ivan

Thanks all of you

Thanks