PDA

View Full Version : Add List value to hyperlink



Emoncada
05-13-2013, 09:22 AM
I have the following code.

ThisWorkbook.FollowHyperlink Address:="http://wwwapps.ups.com/WebTracking/track?HTMLVersion=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

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?

mdmackillop
05-14-2013, 11:52 AM
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.

Emoncada
05-14-2013, 12:04 PM
I have the following that looks for blanks and removes them.
For r = .ListCount - 1 To 0 Step -1
If .List(r, 0) = "" Then
.RemoveItem r
End If
Next r

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

mdmackillop
05-14-2013, 03:50 PM
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
For i = 0 To ListBox1.ListCount - 1
txt = Me.ListBox1.List(i, 0) & "%0D%0A" _
Next

SamT
05-14-2013, 03:56 PM
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

snb
05-15-2013, 02:16 AM
or

ThisWorkbook.FollowHyperlink Address:="http://wwwapps.ups.com/WebTracking/track?HTMLVersion=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