Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Finding attachment point for comment textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josh Sale - 23 May 2008 01:46 GMT
I'm trying to figure out how to navigate from a textbox that contains a
comment object back to the worksheet cell that the comment is associated
with.

The case begins with the user selecting the comment textbox
(TypeName(Selection) = "TextBox" and Selection.ShapeRange.Type = msoComment)
and then running one of my macro's to manipulate the comment.

The textbox's TopLeftCell and BottomRightCell are relative to where the
textbox got popped up (or was moved by the user) so they don't help.

I just can't figure out how to crossover in the Excel object model from the
textbox that is displaying the comment to the Range.Comment that actually
contains the comment.

Any suggestions?

TIA,

josh
Bernie Deitrick - 23 May 2008 02:23 GMT
Josh,

The comment's parent is a range object, which you can find like so:

Sub test()
Dim myComm As Comment
For Each myComm In ActiveSheet.Comments
   MsgBox "The comment for cell " & myComm.Parent.Address & _
   " has the text:" & Chr(10) & """" & myComm.Text & """"
Next myComm
End Sub

HTH,
Bernie
MS Excel MVP

> I'm trying to figure out how to navigate from a textbox that contains a
> comment object back to the worksheet cell that the comment is associated
[quoted text clipped - 16 lines]
>
> josh
Josh Sale - 23 May 2008 19:24 GMT
Sorry Bernie, but this isn't what i'm looking for.

Assume the user has made the comment visible on the worksheet and that they
have then selected the textbox that displays the popped up comment (i.e.,
TypeName(Selection) = "TextBox" and Selection.ShapeRange.Type = msoComment).

How do I get from Selection back to the Comment?

I suppose I could itterate through all of the worksheet's comments and match
the contents of the TextBox with that of each comment ... but if the
worksheet contained two identical comments then my search might identify the
wrong comment.

It just seems like there must be some way to work backward through the
object model to get from the selected comment to the comment object itself.

Is there someway to find all of the little connectors on the worksheet?  If
so, maybe I could find the little line with the arrow head on it that points
from the comment's textbox back to its cell.  If I could find those
connectors then I could look for one that has an endpoint on the comment's
textbox and then use the other endpoint to identify the cell the comment is
associated with and then I'm there.

Does the above make the problem clearer?

Thanks,

josh

> Josh,
>
[quoted text clipped - 32 lines]
>>
>> josh
Bernie Deitrick - 23 May 2008 19:37 GMT
Josh,

Oops, I'm sorry that I misunderstood.  Your explanation does make it clearer. Try

MsgBox ActiveSheet.Comments(Selection.Index).Parent.Address & " is the cell with that comment."

Of course, you will need error checking etc. to make sure that the Selection is actually a comment
or the code will blow up.

HTH,
Bernie
MS Excel MVP

> Sorry Bernie, but this isn't what i'm looking for.
>
[quoted text clipped - 57 lines]
>>>
>>> josh
Josh Sale - 23 May 2008 19:56 GMT
That works great!!!

I have to admit to still being puzzled as to why it works.  When Selection
references a TextBox, why does Selection.Index correctly index into the
worksheet's Comments collection?

Don't get me wrong, I'll take the solution even if its black magic but I
would like to flesh out my understanding of the Excel object model.

Thanks so much!!

josh

> Josh,
>
[quoted text clipped - 79 lines]
>>>>
>>>> josh
Bernie Deitrick - 23 May 2008 20:21 GMT
Josh,

The index value is not referencing a textbox, it is referencing a comment (which is a special kind
of textbox). Each comment has an index (And a name) and the icex can be used to reference the
comment (but the name cannot).  Of course the comment is a member of the comments collection.  And
that is why it works, and why it will blow up if your selection isn't a comment.

HTH,
Bernie
MS Excel MVP

> That works great!!!
>
[quoted text clipped - 82 lines]
>>>>>
>>>>> josh
Josh Sale - 23 May 2008 20:49 GMT
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.