Excel VBA表单控件 – 重置列表框滚动条

我写了下面的代码,从同一张纸上的六个列表框(多选)拉取数据,将select传递给一个模块进行计算,然后清除列表框select。 尽pipe非常令人沮丧的唯一问题似乎微不足道的是获取列表框“滚动条”为每个列表框重置其位置列表的顶部。

我曾尝试.TopIndex,但因为我使用的是一个窗体控件,而不是一个ActiveX控件,它返回“对象”不支持。

有谁知道如何重置列表框滚动条位置顶部的窗体控件列表框?

Sub Listboxproperties_click() 'store selected items from listbox into an array Dim listarray() Dim J As Integer Dim R As Integer Dim i As Integer 'Add selected items into the array ReDim listarray(1 To 50, 1 To 6) 'Counter J = 0 For R = 1 To 6 Set lb = ActiveSheet.ListBoxes("ListBox" & R) For i = 1 To lb.ListCount If lb.Selected(i) = True Then 'add 1 to the counter J = J + 1 'Store selection in an array listarray(J, R) = lb.list(i) End If Next i J = 0 Next R 'Check if msgbox has a selection if not exit sub For R = 1 To 6 'if there is nothing in the first item of the listarray then the user has not chosen an option If listarray(1, R) = "" Then MsgBox "You have not selected a option, please select and retry" Exit Sub End If Next R 'input box for the name of the Trend Linename = InputBox("Please enter a name for the call type you are calculating ie Adviser Calls, Withdrawal Status etc", "Call Trend") If Linename = "" Then MsgBox "No name selected, please retry and enter a name for your call flow" Exit Sub End If Call UniqueCount(listarray, Linename) 'clear selections from listbox For R = 1 To 6 Set lb = ActiveSheet.ListBoxes("ListBox" & R) For i = 1 To lb.ListCount - 1 If lb.Selected(i) = True Then lb.Selected = False End If Next i lb.TopIndex Next R End Sub 

唯一的办法,我发现它是清理并重新插入值…

 Dim xx(1 To 10000) As String Set o = ActiveSheet.Shapes("List Box 1") e = 1 For e = 1 To o.ControlFormat.ListCount xx(e) = o.ControlFormat.List(e) Next o.ControlFormat.RemoveAllItems For i = 1 To e o.ControlFormat.AddItem xx(i) Next o.ControlFormat.ListIndex = 1 

因为ListIndexselect第一个元素,但不是活动的,你不能使用键盘移动里面…

我没有足够的专家来编写代码来帮助你,但我有一个想法可能会工作,你可以试图编写代码或比我们更聪明的人可以帮忙。

你说你正在使用多重select,所以当重置,你可能会做以下几点?

  1. 删除所有select
  2. closures多select单选
  3. select列表框中的第一个项目(即将焦点置于顶部)
  4. 删除此选项
  5. 将此列表框返回到多选

我正在考虑尝试单选的原因是因为多select列表框确定与select不关注所选项目。 这更多的是一个理论,但看到没有人试图回答我想我会帮助。 任何人都可以确认或否认我的想法?