重复更新列表框的内容,同时保持用户控制权 [英] Repeatedly update contents of a list box while maintaining user control
问题描述
在VBA中,我用稳定增长的文本文件的文本反复更新列表框的内容.在我要更新列表框的循环运行时,有什么方法可以让用户保持控制(滚动列表框,按一个按钮)? application.wait的替代方法也可以;例如,更新->等待x秒(用户仍可以在其中进行操作->重新更新->重复.
In VBA, I am repeatedly updating the contents of a list box with the text of a steadily growing text file. Is there any way to let the user maintain control (scroll the list box, press a button) while the loop that I'm in to update the list box is running? An alternative to application.wait would also work; as in, update -> wait x seconds (where the user can still do stuff -> update again -> repeat.
推荐答案
这是一个开始.在常规模块中,粘贴以下代码:
Here's a start. In a regular module, paste this code:
Sub ShowUserForm()
UserForm1.Show vbModeless
End Sub
Sub UpdateTextBox()
Dim ws As Excel.Worksheet
Set ws = ThisWorkbook.Worksheets(1)
With UserForm1.ListBox1
.List = ws.Range("A1:A" & ws.Range("A" & ws.Rows.Count).End(xlUp).Row).Value2
.ListIndex = .ListCount - 1
End With
Application.OnTime Now + TimeValue("00:00:5"), "UpdateTextBox"
End Sub
在用户窗体中,将此代码粘贴到UserForm_Activate事件中:
In your userform paste this code in the UserForm_Activate event:
UpdateTextBox
它使用代码更新工作簿中Sheet1的A列中的值.
It updates the values from column A of Sheet1 in the workbook with the code.
要测试它,请运行ShowUserForm.
To test it, run ShowUserForm.
这篇关于重复更新列表框的内容,同时保持用户控制权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!