简单的VBA显示/隐藏Excel注释问题 [英] Simple VBA Show/Hide Excel Comments problems

查看:243
本文介绍了简单的VBA显示/隐藏Excel注释问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这给我的方式比它应该更麻烦。

This is giving me way more trouble than it should.

我对excel电子表格有意见。我有一个按钮当用户点击按钮时,应该显示评论。当他们再次点击时,评论应该消失。这是我试图使用的代码 - 它们都独立工作,但是当我放入If Then Else语句时,无论我尝试什么都会收到错误:

I have comments on an excel spreadsheet. I have one button. When a user clicks the button, the comments should show. When they click it again, the comments should go away. This 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 no matter what I try:

Sub showcomments()

If Comments <> "Visible" Then Application.DisplayCommentIndicator = xlCommentAndIndicator
Else: Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End If

End Sub

我已经尝试了所有的间距,缩进等等。如果comments = visible,我已经尝试过else什么似乎应该是一个如此简单的任务呢。

I've tried all variations of spacing, indenting, etc. I've tried else if comments = visible; nothing seems to work for what should be such a simple task. I usually get the error "else without if" despite the fact that it's right there.

感谢:)

推荐答案

尝试这样:

   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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆