您好,我正在学习一些我自己的课程,而我正在学习的Udemy课程正在帮助我学习VBA,因此我可以在自己的工作中创建一些Macros,使我看起来很专业。因此,到目前为止,第一个练习是要求我记录一个宏,该宏将从工作簿中删除所有注释。我以为我可以通过使用一些循环来达到班级的领导水平,但是我一直在以为自己很聪明而出错。我一直在cm循环上,对象不再支持该属性或方法。运行时错误438我不明白为什么在执行cm时要考虑这一点。它会打开下拉列表。
Sub delete_Comments()
' just trying to see if the cm loop works because it counted properly with the ws loop
Dim counter As Integer
' so i can use to run through the work sheets
Dim ws As Worksheet
'so I can run through the activesheet
Dim cm As Comment
counter = 0
'loop through the sheets in the workbook
For Each ws In Worksheets
'loop through the comments on active worksheet
For Each cm In ActiveSheet
cm.Delete
counter = counter + 1
Next cm
MsgBox counter
Next ws
End Sub
更新了循环,谢谢@JohnColeman
For Each ws In Worksheets
'clear comments
Selection.SpecialCells(xlCellTypeComments).Select
Selection.ClearComments
counter = counter + 1
Next ws
答案 0 :(得分:2)
这是删除旧式注释的一种方法:
Sub jkdfsh()
Dim c As Comment, w As Worksheet
For Each w In Sheets
k = w.Comments.Count
If k = 0 Then
MsgBox "no comments n sheet " & w.Name
Else
For Each c In w.Comments
c.Delete
Next c
End If
Next w
End Sub