Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Dose anyone know the answer why excel closes down when scrolling down the mouse on listbox? Is there anything I should adjust in the properties? Thanks.

[EDIT]Moved from comment - LOSMAC[/EDIT]

I am using excel 2007, and this is the code used on listbox and it is populated with directories names when I select single directory name other list box will be populated with files names, and whenever I have the listbox active and item is selected and scroll down the mouse I will have the entire workbook goes into closing down and file recovery mode. Is there any way to prevent scrolling down while items are selected? or any other solutions. Thank.

VB
Private Sub ListBox2_Click()
Dim strFile As String
Dim i As Integer

Me.ListBox1.Clear
For i = 0 To Me.ListBox2.ListCount - 1
    If Me.ListBox2.Selected(i) Then
         strFile = Dir("C:\Users\hawari\Documents\TLC\" & Me.ListBox2.Text & "\*.xls")
         Do While Len(strFile) > 0
             ListBox1.AddItem strFile
             strFile = Dir
         Loop
    End If
Next
End Sub
Posted
Updated 27-Nov-11 3:32am
v3
Comments
DaveAuld 27-Nov-11 1:26am    
Sounds like a bug, post the code you are using to scroll and which version of excel you are using.
ahawari09 27-Nov-11 3:25am    
I am using excel 2007, and this is the code used on listbox and it is populated with directories names when I select single directory name other list box will be populated with files names, and whenever I have the listbox active and item is selected and scroll down the mouse I will have the entire workbook goes into closing down and file recovery mode. Is there any way to prevent scrolling down while items are selected? or any other solutions. Thank.
Private Sub ListBox2_Click()
Dim strFile As String
Dim i As Integer
me.ListBox1.Clear
For i = 0 To Me.ListBox2.ListCount - 1
If Me.ListBox2.Selected(i) Then
strFile = Dir("C:\Users\hawari\Documents\TLC\" & Me.ListBox2.Text & "\*.xls")
Do While Len(strFile) > 0
ListBox1.AddItem strFile
strFile = Dir
Loop
End If
Next
End Sub
DaveAuld 27-Nov-11 3:35am    
From what you are saying it sounds like your install of excel or one of the files is corrupt. It shouldn't crash in that way. I would try an over install first or a Repair Install. Failing that uninstall and reinstall.
ahawari09 27-Nov-11 4:08am    
Thank you for your answer. But dose it have anything to do with excel installation? Thanks.
DaveAuld 27-Nov-11 4:53am    
Yes it sounds like something has been corrupted. see my previous comment.

1 solution

In my opinion, the reason of error is not in the procedure "ListBox2_Click".
Probably your file is corrupted. You need to export userform(s) into file(s) /use right click on the userform on the left side of the compilator's window/, then create new Excel file and import the userform(s) from file(s).
I hope, it would be helpful. If not, try to reinstall (repair) MS Office, as DaveAuld said.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900