I have been asked as a subcontractor to extract Vendor IDs from a public list of client entity vendors and do some stuff with them. (It's a very large entity and nobody within the client team I'm working with knows who manages the source data, so I'm shortcutting the detective process). The list is simply copied from the website with click mousedrag, and pastes into Word in a simple non-table line by line format, with additional breaks at each new letter of the alphabet. While the macro works to get the Vendor ID, due to my lack of skill with Word VBA the code returns this odd phenomenon where after the first Vendor ID in each alphabet letter group the subsequent VIDs in the alpha letter display as if they are part of the hyperlink. Can someone advise? All code improvements are welcome, and yes I'm hoping to provide the final macro and technique back to the client team for their future use.
Code: Select all
Sub GetWriteVID()
' Place VID next to vendor name
Dim hloLink As Hyperlink
Dim strAllAddressText As String, strVID As String
Dim lngVIDStartPos As Long
Dim boolHasVID As Boolean
With ActiveDocument
.Paragraphs.TabStops.Add Position:=InchesToPoints(3.5), Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
For Each hloLink In .Hyperlinks
On Error GoTo ERRHANDLER
strAllAddressText = hloLink.Address
lngVIDStartPos = InStr(7, strAllAddressText, "=u", vbTextCompare) + 1
boolHasVID = CBool(lngVIDStartPos - 1)
If boolHasVID Then
strVID = Mid(strAllAddressText, lngVIDStartPos, 8)
hloLink.Range.InsertAfter vbTab & strVID
End If
Next
End With
ERRHANDLER::
If CBool(Err.Number) Then Debug.Print hloLink.Address & vbTab & Err.Number & vbTab & Err.Description
End Sub
Thanks for any help, and again yes, I will make money from this. But that's true for all of us trying to resolve work problems, right?