使用VBA在Excel中显示/隐藏注释 [英] Show/Hide Comments in Excel using VBA
本文介绍了使用VBA在Excel中显示/隐藏注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Excel电子表格上有注释。
I have comments on an Excel spreadsheet.
我有一个按钮来控制是显示还是隐藏注释。当用户单击按钮时,将显示注释。当用户再次单击它时,注释应该消失。
I have one button to control whether the comments are displayed or hidden. When a user clicks the button, the comments should show. When the user clicks it again, the comments should go away.
下面是我要使用的代码-它们都可以独立工作,但是当我输入If Then Else语句时,我收到错误:
Below is the code I'm trying to use - they both work independently, but when I put in an If Then Else statement, I get errors:
Sub showcomments()
If Comments <> "Visible" Then Application.DisplayCommentIndicator = xlCommentAndIndicator
Else: Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End If
End Sub
如果注释=可见,我尝试了 else
。
I tried else if comments = visible
.
我通常会收到错误 else without if ;。
I usually get the error "else without if".
推荐答案
尝试一下:
Sub showcomments()
Comments = 1
For Each MyComments In ActiveSheet.Comments
If MyComments.Visible = True Then
Comments = 0
End If
Next
If Comments = 1 Then
Application.DisplayCommentIndicator = xlCommentAndIndicator
Else
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End If
End Sub
这篇关于使用VBA在Excel中显示/隐藏注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文