You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VBA ActiveX ListBox滚动条点击后无法即时滚动问题求助

ListBox滚动延迟问题求助

我是VBA编程新手,现遇到问题:点击ListBox的上下滚动箭头后,列表不会立即滚动,必须点击工作表任意位置才能触发滚动。相关截图如下:
ListBox滚动异常截图

以下是关联的ListBox2_Change事件代码:

Private Sub ListBox2_Change()
    ' When selecting/deselecting a ListBox items update the checklist and apply 'Not in Scope' for Not applicable checks based on the SW_BTS_CHECKS and SW_SERVICE_CHECKS

    ' If event trigger is disabled, exit the function
    If bDisableLBChange = True Then
        Exit Sub
    End If
    
    Application.ScreenUpdating = False
    
    ' Define worksheet objects
    Dim sh_checks As Worksheet
    Set sh_checks = ActiveWorkbook.Sheets("SW_SERVICE_CHECKS")
    
    Dim sh_pre_align As Worksheet
    Set sh_pre_align = ActiveWorkbook.Sheets("Pre Alignment")
    
    Dim sh_post_align As Worksheet
    Set sh_post_align = ActiveWorkbook.Sheets("Post alignment")
    
    sh_pre_align.Unprotect
    sh_post_align.Unprotect
    
    ' Set all checks to Not in Scope (later the ones in Scope will be emptied)
    Dim rng As Range
    
    sh_pre_align.Activate
    sh_pre_align.Columns(1).SpecialCells(xlCellTypeConstants).Select
    Selection.Offset(0, 10).Value = "Not In Scope"
    Selection.Offset(0, 12).Value = "Not In Scope"
    
    sh_post_align.Activate
    sh_post_align.Columns(1).SpecialCells(xlCellTypeConstants).Select
    Selection.Offset(0, 11).Value = ""
    
    ' Display Not in Scope, Post Align tab
    Selection.Offset(0, 12).Value = ""
    
    ' Define arrays for storage
    Dim arr_pre_align() As String
    Dim arr_post_align() As String

    ' Loop through selection of hardware one-by-one
    Dim nSelected As Integer
    
    For lItem = 0 To Me.ListBox2.ListCount - 1
    
        If Me.ListBox2.Selected(lItem) Then
                        
            nSelected = nSelected + 1
            
            ' Collect pre-align checks to perform from the SW_SERVICE_CHECKS sheet
            arr_pre_align = Split(sh_checks.Cells(lItem + 2, 2), ",")
            arr_post_align = Split(sh_checks.Cells(lItem + 2, 3), ",")
            
            ' For each ID assigned to the hardware, delete the Not in Scope and replace by empty value (so check has to be performed)
            ' First check the pre-alignment checks
            For Each str_pre In arr_pre_align
                With sh_pre_align.Columns(1)
                    Set c = .Find(str_pre, LookIn:=xlFormulas, LookAt:=xlWhole)
                    If Not c Is Nothing Then
                        c.Offset(0, 10).Value = ""
                        c.Offset(0, 12).Value = ""
                    End If
                End With
            Next str_pre
            
            ' Second check the post-alignment checks
            For Each str_post In arr_post_align
                With sh_post_align.Columns(1)
                    Set c = .Find(str_post, LookIn:=xlFormulas, LookAt:=xlWhole)
                    If Not c Is Nothing Then
                        c.Offset(0, 11).Value = ""
                        c.Offset(0, 12).Value = ""
                    End If
                End With
            Next str_post
            
        End If
        
    Next lItem
    
    ' If no items are selected, reset the checklists by emptying all Not in Scope entries
    If nSelected = 0 Then
        sh_pre_align.Activate
        sh_pre_align.Columns(1).SpecialCells(xlCellTypeConstants).Select
        Selection.Offset(0, 10).Value = ""
        Selection.Offset(0, 12).Value = ""
        
        sh_pre_align.Columns.EntireColumn.Hidden = False
        sh_pre_align.Rows.EntireRow.Hidden = False
        
        sh_post_align.Activate
        sh_post_align.Columns(1).SpecialCells(xlCellTypeConstants).Select
        Selection.Offset(0, 11).Value = ""
        Selection.Offset(0, 12).Value = ""
        sh_post_align.Columns.EntireColumn.Hidden = False
        sh_post_align.Rows.EntireRow.Hidden = False
        
    End If
    
    sh_pre_align.Protect
    sh_post_align.Protect
    
    ActiveWorkbook.Sheets("Configure Checklist").Activate
    Application.ScreenUpdating = True
    
End Sub

我不确定需要调整控件属性还是修改代码来解决该问题,恳请各位帮忙解答。

内容的提问来源于stack exchange,提问作者Felipe Kawashima

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 06:35:07