Consulting

Results 1 to 6 of 6

Thread: Add List value to hyperlink

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Add List value to hyperlink

    I have the following code.

    [VBA]ThisWorkbook.FollowHyperlink Address:="http://wwwapps.ups.com/WebTracking/t...=5.0&loc=en_US&" _
    & "Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums=" _
    & Me.ListBox1.List(0, 0) & "%0D%0A" _
    & Me.ListBox1.List(1, 0) & "%0D%0A" _
    & Me.ListBox1.List(2, 0) & "%0D%0A" _
    & Me.ListBox1.List(3, 0) & "%0D%0A" _
    & Me.ListBox1.List(4, 0) & "%0D%0A" _
    & Me.ListBox1.List(5, 0) & "%0D%0A" _
    & Me.ListBox1.List(6, 0) & "%0D%0A" _
    & Me.ListBox1.List(7, 0) & "%0D%0A" _
    & "&track.x=Track", NewWindow:=True[/VBA]

    I have a listbox that gets populated from a spreadsheet.
    This form will show the tracking #'s and with a click it checks all tracking numbers on UPS Website in group.
    List box can have upto 25 rows, but lets say
    Me.ListBox1.List(7, 0) = "" then it won't work.

    How can I have it look at just the values in listbox and then have it add those to the hyperlink?

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If a blank entry in the listbox is the issue then join them in a string value first, correcting for the omission, and appending that string to the address.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    I have the following that looks for blanks and removes them.
    [VBA] For r = .ListCount - 1 To 0 Step -1
    If .List(r, 0) = "" Then
    .RemoveItem r
    End If
    Next r[/VBA]

    The Problem I have is how do I get the correct information into the hyperlink?

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    What text string is generated by your listbox values when a Blank is included?
    if the Listcount changes, i thonk your code needs to be dynamic. Something like
    [VBA]For i = 0 To ListBox1.ListCount - 1
    txt = Me.ListBox1.List(i, 0) & "%0D%0A" _
    Next
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    [vba]For r = 0 To ListBox1.ListCount - 1
    If .List(r, 0) <> "" Then
    linkList = linkList & List(r, 0) & "%0D%0A"
    End If
    Next r
    'If you KNOW the List box will never be competly empty, you can
    'omit the If Right and End If lines
    If Right(linkList, 6) = "%0D%0A" Then
    linkList = Left(linkList, Len(linkList) - 6)
    End If

    EntireLink = EntireLink & linkList[/vba]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    or
    [vba]
    ThisWorkbook.FollowHyperlink Address:="http://wwwapps.ups.com/WebTracking/t...=5.0&loc=en_US&" _
    & "Requester=UPSHome&WBPM_lid=homepage%2Fct1.html_pnl_trk&trackNums="_
    & Replace(Replace(Join(Application.Transpose(ListBox1.List), "%0D%0A"), "%0D%0A%0D%0A", "%0D%0A"), "%0D%0A%0D%0A", "%0D%0A") & "&track.x=Track", NewWindow:=True

    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •