Excel VBA Listbox links

HumanlyRespectable

I currently have a macro with two columns and many rows. The two columns holds info such as First name and a link to a folder or website.

When i click the button on the macro, it takes all the info from the excel sheet and shows the first name and places it in a listbox.

I was wondering, is it possible that when i click the button, i displays the first name in the listbox but also stores a link? when i select an item in the listbox, i want it to open up the link. is this possible?

i have thought of one way, and that is with the listbox and an array which stores the link, and when i click on an item, it searches the array and then opens the link, FOR EXMAPLE: if i click the first item in the listbox, it will go into the array and go to array(1) and then get that link.

That is one way i thought of but is there an easier way? rather than i storing the link into an array and all that.

the current code that i have is:

For row = 3 To 10
    ListBox1.AddItem Range("A" & row).Text
Next

i don't know how to add a hyperlink to this code

Dmitry Pavliv

Update:

What I would do is create Listbox with two columns:

Private Sub UserForm_Initialize()
    Dim row As Integer

    ListBox1.ColumnCount = 2
    ListBox1.ColumnWidths = "50;150"
    For row = 3 To 10
        ListBox1.AddItem Range("A" & row).Text
        ListBox1.List(ListBox1.ListCount - 1, 1) = Range("B" & row).Text
    Next
End Sub

Here is ListBox1_DblClick handler (when user double clicked on listbox item):

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    On Error GoTo ErrHandler
    ThisWorkbook.FollowHyperlink Address:=ListBox1.List(ListBox1.ListIndex, 1)
ExitHere:
    Exit Sub
ErrHandler:
    If Err.Number = -2147221014 Then
        MsgBox "Wrong link!"
    Else
        MsgBox "Error: " & Err.Description
    End If
    Resume ExitHere
End Sub

Then you can double click on any item in listbox to follow hyperlink:

enter image description here

Also I suggest you to change Range("A" & row).Text to ThisWorkbook.Worksheets("Sheet1").Range("A" & row).Text

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel VBA Listbox links

From Dev

Listbox excel vba

From Dev

Excel - Links Not Updating with VBA

From Dev

Excel VBA loop through listbox

From Dev

Excel VBA ActiveX ListBox not allowing click

From Dev

How to declare and set a ListBox variable in Excel VBA?

From Dev

Listbox not returning data correctly in excel vba

From Dev

VBA Excel populate single cell with listbox items

From Dev

.Offset when copy the data to ListBox - Excel VBA

From Dev

VBA Excel: Show visible cells in listbox only

From Dev

Excel VBA ActiveX ListBox not allowing click

From Dev

Excel VBA Add Item below ListBox Selection

From Dev

VBA listbox copy to listbox

From Dev

VBA listbox copy to listbox

From Dev

Excel VBA: Searching for value in listbox based on value set in textbox

From Dev

VBA EXCEL: Use value in Listbox as Lookup value in the Match WorksheetFunction

From Dev

Excel VBA: ListBox-UserForm Variable creation issue

From Dev

Excel VBA Form Control - Reset Listbox Scroll Bar

From Dev

Excel VBA Listbox - Only Format non blanks as Dates

From Dev

Excel VBA: Searching for value in listbox based on value set in textbox

From Dev

Why ListBox doesn't have a FindString method in Excel-VBA?

From Dev

Excel VBA - listbox.selected property causing error

From Dev

Excel 2010 VBA transfer multicolumn Listbox to named range

From Dev

Excel VBA - How To Deselect A Previosuly Selected Item In A Listbox

From Dev

VBA MACRO - Dynamically Select Columns in Excel Using ListBox

From Dev

Excel VBA multiple selection ListBox check if nothing is selected

From Dev

How to multiselect more than one listbox simultaneously in excel VBA

From Dev

Excel VBA Populate Listbox1 based on Listbox2 Selection

From Dev

Excel VBA Populate Listbox1 based on Listbox2 Selection

Related Related

  1. 1

    Excel VBA Listbox links

  2. 2

    Listbox excel vba

  3. 3

    Excel - Links Not Updating with VBA

  4. 4

    Excel VBA loop through listbox

  5. 5

    Excel VBA ActiveX ListBox not allowing click

  6. 6

    How to declare and set a ListBox variable in Excel VBA?

  7. 7

    Listbox not returning data correctly in excel vba

  8. 8

    VBA Excel populate single cell with listbox items

  9. 9

    .Offset when copy the data to ListBox - Excel VBA

  10. 10

    VBA Excel: Show visible cells in listbox only

  11. 11

    Excel VBA ActiveX ListBox not allowing click

  12. 12

    Excel VBA Add Item below ListBox Selection

  13. 13

    VBA listbox copy to listbox

  14. 14

    VBA listbox copy to listbox

  15. 15

    Excel VBA: Searching for value in listbox based on value set in textbox

  16. 16

    VBA EXCEL: Use value in Listbox as Lookup value in the Match WorksheetFunction

  17. 17

    Excel VBA: ListBox-UserForm Variable creation issue

  18. 18

    Excel VBA Form Control - Reset Listbox Scroll Bar

  19. 19

    Excel VBA Listbox - Only Format non blanks as Dates

  20. 20

    Excel VBA: Searching for value in listbox based on value set in textbox

  21. 21

    Why ListBox doesn't have a FindString method in Excel-VBA?

  22. 22

    Excel VBA - listbox.selected property causing error

  23. 23

    Excel 2010 VBA transfer multicolumn Listbox to named range

  24. 24

    Excel VBA - How To Deselect A Previosuly Selected Item In A Listbox

  25. 25

    VBA MACRO - Dynamically Select Columns in Excel Using ListBox

  26. 26

    Excel VBA multiple selection ListBox check if nothing is selected

  27. 27

    How to multiselect more than one listbox simultaneously in excel VBA

  28. 28

    Excel VBA Populate Listbox1 based on Listbox2 Selection

  29. 29

    Excel VBA Populate Listbox1 based on Listbox2 Selection

HotTag

Archive