当前位置:首页 > Excel VBA教程 > 自动调整批注大小

自动调整批注大小

来源:Excel中文网 作者:Excelcn 发布时间:2006-05-09
在这前,本站中一篇文章中说过利用AutoSize属性,来自动调整批注大小:

http://www.excelba.com/showart.asp?cat_id=12&art_id=65

但AutoSize 属性也只能是自动调整批注框框的宽度,使批注在一行中全部显示出来。如何在设定批注的文本框的宽度固定的情况下,使高度自动调整以适应其中所包含的文字?设宽度为150,请看以下的代码:
Sub Comments_AutoSize()
Dim MyComments As Comment
Dim lArea As Long
For Each MyComments In ActiveSheet.Comments
With MyComments
.Shape.TextFrame.AutoSize = True
If .Shape.Width <> 150 Then
lArea = .Shape.Width * .Shape.Height ’ 将批注转成面积
.Shape.Width = 150
.Shape.Height = (lArea / 150)
End If
End With
Next
End Sub
| 网站地图 All Rights Reserved. Powered by Excel中文网