excel中vba添加批注的方法,以及使用单元格现有内容添加到批注框里的案例和代码写法
时间:2023-07-31 11:05:12
本文整理两个excel中使用vba添加批注的案例,分享给大家学习。
vba添加批注案例一:
为选中的一个单元格自动添加批注,批注内容为系统当天日期,然后标注外框大小自动调整为刚好容纳内容即可,因为默认的批注比较大。
效果如下图,比如单击A1,然后自动加批注,选中A4,又自动添加批注,以此类推。
实现上面的效果vba添加批注的代码如下:
Sub vba添加批注()
On Error Resume Next
ActiveCell.AddComment
With ActiveCell.Comment
.Text CStr(Date)
.Shape.TextFrame.AutoSize = True
End With
End Sub
vba添加批注案例二:
为B列的姓名使用VBA添加批注,要求批注内容为C列单元格对应的的内容,而且批注框内文字大小为11号字体,不加粗,且随内容的多少自动调整批注框的格式的大小。
相关的代码如下:
Sub vba添加批注()
Dim strComment As String
Dim yWidth As Long
Endrow = Sheet1.[B65536].End(xlUp).Row
For sn = 2 To Endrow
With Sheet1.Cells(sn, 2)
strComment = Sheet1.Cells(sn, 3)
If .Comment Is Nothing Then '没有备注则添加备注
.AddComment Text:=strComment
.Comment.Visible = False
Else '已经有备注则备注添加内容
.Comment.Text Text:=strComment
End If
With .Comment.Shape
.TextFrame.Characters.Font.Size = 11
.TextFrame.AutoSize = True
If .Width > 250 Then
yWidth = .Width * .Height
.Width = 150
.Height = (yWidth / 200) * 1.8
End If
End With
End With
Next sn
End Sub
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Win10怎么开启禁用的网络连接?Win10开启禁用的网络连接方法
![](https://img.aspxhome.com/file/2023/1/a279615_0s.jpg)
ppsspp模拟器金手指怎么用?ppsspp模拟器启用金手指的方法
![](https://img.aspxhome.com/file/2023/7/a327103_0s.png)
win7电脑关闭闲置服务的方法?
![](https://img.aspxhome.com/file/2023/3/a296343_0s.jpg)
After Effects 教程「36」,如何在 After Effects 中创建透明度?
![](https://img.aspxhome.com/file/2023/1/a202401_0s.jpeg)
Excel中如何插入其他表格
![](https://img.aspxhome.com/file/2023/0/a153760_0s.png)
Win7运行快捷键有何方法?
![](https://img.aspxhome.com/file/2023/27/a231805_0s.jpg)
win7系统怎样实现内外网同时连接的教程
Win10投影仪怎么设置 Win10投影仪设置详细介绍
![](https://img.aspxhome.com/file/2023/25/a218108_0s.jpg)
操作系统启动慢的原因分析
Win10重置失败未做更改怎么处理?
![](https://img.aspxhome.com/file/2023/6/52506_0s.png)
Word2003删除空白页 Word怎么删除空白页的方法小结[图文]
![](https://img.aspxhome.com/file/2023/6/29726_0s.jpg)
金山在线文档怎么用
![](https://img.aspxhome.com/file/2023/3/a184383_0s.jpg)
在wps表格中怎样设置密码
Win7旗舰版更新显卡驱动后蓝屏了怎么办?
![](https://img.aspxhome.com/file/2023/27/a229507_0s.jpg)
在word中如何简单输入根号呢?
![](https://img.aspxhome.com/file/2023/6/23826_0s.jpg)
为什么这么多人推荐火绒?火绒真的比360好吗?
![](https://img.aspxhome.com/file/2023/7/a328508_0s.jpg)
qq群名片怎么改?qq群名片的修改方法
![](https://img.aspxhome.com/file/2023/6/a325815_0s.jpg)
Win7小键盘NumLock键失效了怎么办?
![](https://img.aspxhome.com/file/2023/29/a251236_0s.jpg)
电脑版WPS演示文稿修改思维导图的连线颜色
![](https://img.aspxhome.com/file/2023/0/a182850_0s.png)
WPS excel多列数据合并为单列
![](https://img.aspxhome.com/file/2023/7/a184967_0s.png)