在一个Sheels中需要循环边历所有的单元格,如果单元格包含批注,则先获取批注信息,再删除当前批注,然后修改获取到的批注信息并重新保存到当前单元格,请问该如何实现?
Tao = Newwb.Sheets("bb").Cells(1, 8)
For k = 5 To 120
If Newwb.Sheets("aa").Cells(k, 2) = Tao Then
这里判断此单元格是否有批注
有则获取当前批注信息
并修改
再删除当前单元格的批注
最后将修改后的批注信息重新添加到单元格
End If
Next
------解决方案--------------------------------------------------------
Sub Comm1()
Dim strCommet As String
On Error Resume Next
If (Range("A1").Comment Is Nothing) Then //如果注释为空
Range("A1").AddComment //增加注释
Range("A1").Comment.Text Text:="abcdefg" //注释内容为"abcdefg"
Else
strCommet = Range("A1").Comment.Text //如果注释不为空
strCommet = strCommet & " modify" //修改注释+ "modify"
Range("A1").ClearComments //清除注释
Range("A1").AddComment //增加注释
Range("A1").Comment.Text Text:=strCommet //设置注释内容
End If
End Sub
------解决方案--------------------------------------------------------
- VB code
Sub 批量修改批注() Dim myRange As Range Dim Rng As Range Dim msg As String Set myRange = Cells.SpecialCells(xlCellTypeComments) For Each Rng In myRange MsgBox Rng.Comment.Text msg = InputBox("请输入新的批注内容", "修改批注") If msg <> "" Then Rng.Value = msg Rng.Comment.Delete End If Next RngEnd Sub