你好 Stackoverflow 社区
我需要有关 ListBox 错误的帮助。
我在工作表中有两个列表框(单选)而不是在用户表单中
ListBox1 - 包含主要项目
ListBox2 - 包含与主要项目关联的子项目
选择主要项目时 -
如果不存在子项,ListBox2.Visible = False
如果子项存在,ListBox2.Visible = True 和 .ListIndex = -1(准备子项选择)
使用工作簿时代码运行完美
问题 打开工作簿时,链接到 ListBox1 的宏将自动运行并弹出错误,并以蓝色突出显示“.ListBox2”
Error = '编译错误:找不到方法或数据成员'
错误不会一直发生,并且工作簿是否保存时 ListBox2 是否可见,或者是否选择了子项都无关紧要。
我曾尝试在打开的工作簿事件上使用,但错误出现在这些事件之前。
请帮忙
添加了发生错误的代码
Dim ListBox2 As ListObject 'Added this in to see if it fixes error but it has not
With Sheet3.ListBox2
.Height = 208.5
.Width = 126.75
.Top = 312.75
.Left = 31.5
.Visible = False
End With