Hyperlinks are not added in run mode but they are in debug mode

I’m running Excel version 2408. The following code populates two tables using a query connection and then adds some hyperlinks. The hyperlinks are added correctly for the first table (tblNoStop) but not for the second (tblNoOffice).

If I put a break before the loop that populates the hyperlinks for the second table and then hit F5 from the debugger, everything works fine.

I have tried adding the DoEvents instruction and forced a wait time of up to one minute, but no success.

I also tried commenting out the first loop, but the result is the same: hyperlinks in table tblNoOffice are only added in debug mode.

Does anybody have an idea?

Here is the relevant part of my code:

'For each liine of the tables update hyperlinks
For RowCounter = 1 To tblNoStop.ListRows.Count
    
    'Add link to the staff  details in the ADAM web application
    Set HLRange = tblNoStop.DataBodyRange(RowCounter, NOSTOP_INDEXCOLIND)
    Call AddHL(HLRange, _
        wsNoStop, _
        "https://adam.unctad.unctad.org/StaffDetails.aspx?id=" & tblNoStop.DataBodyRange(RowCounter, NOSTOP_INDEXCOLIND).Value & "&activemenu=1", _
        "", _
        SCRTIP & tblNoStop.DataBodyRange(RowCounter, NOSTOP_FIRSTNAMECOLIND).Text & " " & tblNoStop.DataBodyRange(RowCounter, NOSTOP_LASTNAMECOLIND) & ADAMWEB)

    'Add link to the staff requests' list in the ADAM web application
    Set HLRange = tblNoStop.DataBodyRange(RowCounter, NOSTOP_STOPACCCOLIND)
    Call AddHL(HLRange, _
        wsNoStop, _
        "https://adam.unctad.unctad.org/RequestList.aspx?id=" & tblNoStop.DataBodyRange(RowCounter, NOSTOP_INDEXCOLIND).Value & "&activemenu=1", _
        "", _
        SCRTIP & tblNoStop.DataBodyRange(RowCounter, NOSTOP_FIRSTNAMECOLIND).Text & " " & tblNoStop.DataBodyRange(RowCounter, NOSTOP_LASTNAMECOLIND) & ADAMREQ)
    
    'Add link to the staff's equipment assignment history
    Set HLRange = tblNoStop.DataBodyRange(RowCounter, NOSTOP_FIRSTNAMECOLIND)
    Call AddHL(HLRange, _
        wsNoStop, _
        "https://adam.unctad.unctad.org/itinventory/EquipmentAssignment.aspx?id=" & tblNoStop.DataBodyRange(RowCounter, NOSTOP_INDEXCOLIND).Value & "&type=2&search=h", _
        "", _
        SCRTIP & tblNoStop.DataBodyRange(RowCounter, NOSTOP_FIRSTNAMECOLIND).Text & " " & tblNoStop.DataBodyRange(RowCounter, NOSTOP_LASTNAMECOLIND) & ADAMASS)
Next

Set tblNoOffice = wsNoStop.ListObjects("NoOffice")
wsNoStop.Activate
DoEvents
'Application.Wait (Now + TimeValue("00:01:05"))

For RowCounter = 1 To tblNoOffice.ListRows.Count

    'Add link to the staff  details in the ADAM web application
    Set HLRange = tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_INDEXCOLIND)
    Call AddHL(HLRange, _
        wsNoStop, _
        "https://adam.unctad.unctad.org/StaffDetails.aspx?id=" & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_INDEXCOLIND).Value & "&activemenu=1", _
        "", _
        SCRTIP & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_FIRSTNAMECOLIND).Text & " " & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_LASTNAMECOLIND) & ADAMWEB)
        DoEvents
    
    'Add link to the staff requests' list in the ADAM web application
    Set HLRange = tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_ADACCEXPCOLIND)
    Call AddHL(HLRange, _
        wsNoStop, _
        "https://adam.unctad.unctad.org/RequestList.aspx?id=" & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_INDEXCOLIND).Value & "&activemenu=1", _
        "", _
        SCRTIP & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_FIRSTNAMECOLIND).Text & " " & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_LASTNAMECOLIND) & ADAMREQ)


    'Add link to the staff's equipment assignment history
    Set HLRange = tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_FIRSTNAMECOLIND)
    Call AddHL(HLRange, _
        wsNoStop, _
        "https://adam.unctad.unctad.org/itinventory/EquipmentAssignment.aspx?id=" & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_INDEXCOLIND).Value & "&type=2&search=h", _
        "", _
        SCRTIP & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_FIRSTNAMECOLIND).Text & " " & tblNoOffice.DataBodyRange(RowCounter, NOOFFICE_LASTNAMECOLIND) & ADAMASS)
Next

Sub AddHL(HLRng As Range, Tgtws As Worksheet, tgtAddr As String, SubAddr As String, SCRTIP As String, Optional DispTxt As Variant)
'Colours list can be found at  http://dmcritchie.mvps.org/excel/colors.htm

On Error GoTo ErrHandler

If IsMissing(DispTxt) Then
    
    Tgtws.Hyperlinks.Add _
    Anchor:=HLRng, _
    Address:=tgtAddr, _
    SubAddress:=SubAddr, _
    ScreenTip:=SCRTIP, _
    TextToDisplay:=HLRng.Text
Else
    Tgtws.Hyperlinks.Add _
    Anchor:=HLRng, _
    Address:=tgtAddr, _
    SubAddress:=SubAddr, _
    ScreenTip:=SCRTIP, _
    TextToDisplay:=DispTxt
End If
Exit Sub
ErrHandler:
    If Err.Number <> 0 Then
    MsgBox "Error #" & Str(Err.Number) & " was generated by " _
         & Err.Source & Chr(13) & "Error Line: " & Erl & Chr(13) & Err.Description, , "Error in subroutine AddHL (Module1)" & _
         "", Err.HelpFile, Err.HelpContext
    End If
End Sub

9

Thanks to the comment made by @CHill60, I added the line

ThisWorkbook.Connections("Query - NoOffice").OLEDBConnection.BackgroundQuery = False

and the problem disappeared.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật