Home » Questions » Computers [ Ask a new question ]

How to add URL in a cell comment using VBA?

How to add URL in a cell comment using VBA?

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 ?

Asked by: Guest | Views: 67
Total answers/comments: 2
Guest [Entry]

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:

Open your workbook in Excel.
Select Insert menu > Picture > Autoshapes. Select a rectangle.
Place one rectangle anywhere on the sheet you want to work with.
Edit the text and make it say whatever you like, including a hyperlink.
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.
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

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!
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!"
Guest [Entry]

"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."