How to add URL in a cell comment using VBA?

3

I am using Microsoft Excel 2003 wherein i have a cell which has a comment. The comment has text as well as URL. Is it possible to create a hyperlink (URL) in comment box where user can click and it automatically opens the URL ?

Thanks,

James

Posted 2010-02-02T17:04:16.503

Reputation: 535

Answers

1

James, If it were me, I would keep this as simple as possible. I'd just have a brightly colored box somewhere out of the way with these guidelines and the link.

If you're interested though, here are steps you can follow to insert the VBA to create a pop-up rectangle text box next to the currently selected cell with whatever text you want it to say:

  1. Open your workbook in Excel.
  2. Select Insert menu > Picture > Autoshapes. Select a rectangle.
  3. Place one rectangle anywhere on the sheet you want to work with.
  4. Edit the text and make it say whatever you like, including a hyperlink.
  5. Select the frame of that rectangle (not the text inside) and then find the name box in the upper-left corner of Excel. It will probably be named something like "Rectange11" now. Change the name to, "Guideshape" (since that's what the code looks for). 6.Right-click the sheet's tab at the bottom of Excel and select View Code.
  6. Paste this code into the big empty text area on the right side of the screen:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        Application.EnableEvents = False
    
        On Error Resume Next
    
        Shapes("GuideShape").Visible = msoFalse
    
        If Not Intersect(Target, Range("C5:C8")) Is Nothing Then
    
            With Me.Shapes("Guideshape")
                 .Visible = msoTrue
                 .Top = Target.Top
                 .Left = Target.Left + 150
            End With
        End If
    
        On Error GoTo 0
    
        Application.EnableEvents = True
    
    End Sub
    
  7. Look for the line that has ("C5:C8") and change that include your range of editable cells where this message should pop-up. Keep the parentheses and double-quotes!

  8. Close the VB editor and return to Excel.

Now whenever you click in a cell in the range you entered into the code, the rectangle you created should appear to the right of that cell. Play with the TOP and LEFT numbers in the code to change that position.

Good luck!

Peter

Posted 2010-02-02T17:04:16.503

Reputation: 290

1

No, you can't create a hyperlink in a comment. You can only insert the URL text.

Hyperlinks is a property of a Range or Worksheet (which comments aren't). There's also a Hyperlink property for a Shape, but that wouldn't apply here (though there might be some really tricky way you could have an image cover the commment and provide the hyperlink).

Lance Roberts

Posted 2010-02-02T17:04:16.503

Reputation: 7 895

Actually this worksheet is a assessment sheet where user is expected to fill data based on certain guidelines. So user would get the guidelines when mouse is over this cell and accordingly he can fill data for this cell. (Last line in this guideline has a reference to the URL to view more information - which would be nice to have clickable URL).

And above behavior is true for all cells in that column.

I am not able to think of any other way to design this. Any suggestions ? – James – 2010-02-02T19:17:37.380

@James, You might add a small column next to that one with hyperlinks in them, maybe a label of 'more?', OR if you're really into programming you can use VBA, and trigger off of one of the events, so that when the user clicks in the cell, a small graphic or textbox pops up with the information, and that can hold a hyperlink. – Lance Roberts – 2010-02-03T22:19:06.733

I am not familiar with event triggering. I will try to look into that option as well. Thanks Lance ! I see an opportunity for Microsoft to add URL option in the comment :) – James – 2010-02-05T09:07:48.897

0

I don't think Excel supports hyperlinks in comments. VBA will likely not help you there.

Could you not put URLs on a column next to your cells instead?

If you're strongly determined to have some sort of tooltip link, you could probably program a tooltip behavior from scratch in VBA (create little yellow form, place it next to cell, hide it when user clicks on another cell, etc..) but that would work separately from the real comments, and probably a few things wouldn't integrate very well, and probably not a very good idea anyway.

mtone

Posted 2010-02-02T17:04:16.503

Reputation: 11 230