I understand that this is a fairly old thread but I couldn't find any other bulletin board on the Internet where this problem was described exactly as I see it.
I have a macro with 3 user forms that are all modal and either one of them is visible depending on user action (clicking on next/previous buttons). The user runs the macro by clicking a button in the Excel workbook. When transitioning from one form to the next, I hide the current form and show the next one. Forms are unloaded only when exiting the macro (which happens when the user clicks on a couple of buttons on each of the forms). The forms themselves are simply for text input and one of the buttons on the form causes the values entered in the form to be committted to a sheet in the excel workbook.
Intermittently, I get the "Run-time error 75: Could not find specified object" popup when I try to re-run the macro. When I hit Debug it goes to the code where the first user form is being loaded. Sometimes, when I am making changes to the
VB code (while the macro is not running) and I try to save the workbook, Excel crashes.
I have not been able to notice
The code used for unloading forms is:
<code
Dim form As UserForm
For Each form In VBA.UserForms
Unload form
Next form
</code
I have also used the following (which is the code suggested by Jim Cone), but the problem still remains and I think this loop is functionally equivalent to the above loop anyways:
<code
For i = VBA.UserForms.Count - 1 To 0 Step -1
Unload VBA.UserForms(i)
Next i
</code
I have gone through my code several times and I feel that this is a bug in Excel, but given that not many people have reported it, I am starting to wonder what might be causing it. Can someone help?
Quote:
Originally Posted by ZipCurs
Jim,
Thanks for the advice. In the end, I just threw an "Unload UserFormXX" at
the end of each macro that was giving me problems. This seems to have done
the trick, although I have not dug in to figure out why the earlier Unload
command did not work.
Thanks again.
"Jim Cone" wrote:
Oops - comment 4 code should be...
lngCounter = UserForms.Count
If lngCounter 0 Then
For N = lngCounter to 1 Step -1 '<<this line changed
Unload UserForms(N - 1)
Next
End If
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)
|