PC Review


Reply
Thread Tools Rate Thread

Comment or not

 
 
Alan
Guest
Posts: n/a
 
      24th Oct 2007
Is there an easy way within VBA to determine whether a give cell on a
worksheet has a comment associated with it or not?

Alan

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      24th Oct 2007
If Not ACtivecell.Comment Is Nothing Then
MsgBox "has coment"
....

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Alan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there an easy way within VBA to determine whether a give cell on a
> worksheet has a comment associated with it or not?
>
> Alan
>



 
Reply With Quote
 
paul.robinson@it-tallaght.ie
Guest
Posts: n/a
 
      24th Oct 2007
Hi
What most people do is

On error resume next
myCell.AddComment
On Error Goto 0

If there is no comment on the cell then one is added, and if one
exists then nothing happens. Now simply carry on with whatever you
want to do with the comment.

If you really need to know that a comment exists or not try

Public Function DoesCommentExist(myCell As Range) As Boolean
Dim myComment As Shape
DoesCommentExist = False
Err.Clear
On Error Resume Next
Set myComment = myCell.Comment.Shape
If Err.Number = 0 Then DoesCommentExist = True
End Function

Run this macro on the activecell with and without a comment. Sub
tester()
MsgBox DoesCommentExist(ActiveCell)
End Sub

Interestingly, Set myComment = myCell.Comment does not work and always
returns true.
regards
Paul


On Oct 24, 11:31 am, Alan <alan.do...@virgin.net> wrote:
> Is there an easy way within VBA to determine whether a give cell on a
> worksheet has a comment associated with it or not?
>
> Alan



 
Reply With Quote
 
Alan
Guest
Posts: n/a
 
      24th Oct 2007
On 24 Oct, 11:40, "Bob Phillips" <bob....@somewhere.com> wrote:
> If Not ACtivecell.Comment Is Nothing Then
> MsgBox "has coment"
> ...
>
> --
> ---
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Alan" <alan.do...@virgin.net> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > Is there an easy way within VBA to determine whether a give cell on a
> > worksheet has a comment associated with it or not?

>
> > Alan- Hide quoted text -

>
> - Show quoted text -


Thanks Bob, that was just what I needed. I was using "On Error" as
Paul was suggesting but I have so many cases to consider my "GoTos"
were getting a bit complicated.

Alan

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      24th Oct 2007

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> Interestingly, Set myComment = myCell.Comment does not work and always
> returns true.



What do you mean Paul? If myComment is a Comment object, that code will
either return Nothing or the comment object.


 
Reply With Quote
 
paul.robinson@it-tallaght.ie
Guest
Posts: n/a
 
      26th Oct 2007
On Oct 24, 3:03 pm, "Bob Phillips" <bob....@somewhere.com> wrote:
> <paul.robin...@it-tallaght.ie> wrote in message
>
> news:(E-Mail Removed)...
>
> > Interestingly, Set myComment = myCell.Comment does not work and always
> > returns true.

>
> What do you mean Paul? If myComment is a Comment object, that code will
> either return Nothing or the comment object.


Hi Bob,
Just me not thinking it through. I thought Set myComment =
myCell.AddComment would raise an error if myCell had no comment, but
it doesn't of course, it just returns Nothing. The code was inside an
On Error... block so I couldn't see the none existent error!
regards
Paul

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit Comment erases part of screen; comment uneditable Charles Blaquière Microsoft Excel Discussion 0 10th Sep 2008 08:31 PM
Mouse-over on comment highlights barely shows comment text GordonM Microsoft Word Document Management 0 9th Apr 2008 01:13 AM
Comment features - changing the colour of comment ballons =?Utf-8?B?TG9vcHN0ZXI=?= Microsoft Word Document Management 1 10th Jun 2007 10:19 PM
a comment plugin & copy paste directly from excel to comment ? fr. =?Utf-8?B?UkZN?= Microsoft Excel Worksheet Functions 0 1st Dec 2004 11:29 PM
Re: after updating or entering a comment, the date is entered into that comment John Vinson Microsoft Access 0 4th Jun 2004 01:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:37 PM.