UserForm_Initialize is not recognized??

  • Thread starter Thread starter Sam Kuo
  • Start date Start date
S

Sam Kuo

Hi

I have one form and an event procedure UserForm_Initialize().

This event procedure was working fine before, but somehow Excel doesn't seem
to recognize the form now (i.e. when I put the cursor within that event
procedure, the object dropdown in the top middle of VB window now shows
"(General)", and "Userform_Initialize" in the event dropdown in the top left)

Please help me!!

Sam
 
And you're sure your in the userform module?

My second guess is that even though you typed in the correct spelling in your
post, you have a typo in your actual code.

I'd change the lefthand side dropdown to Userform and then choose Initialize
from the righthand side. Maybe you'll see the typo--or just delete the line
with the typo and move the generated line to where it belongs.
 
Are you sure you have your code in the UserForm's code window?

Rick
 
Hi Dave

1) Yes, the code is in the userform module as before when it was still
working.
2) There is no "UserForm" for me to select from the lefthand side dropdown.
But the form does exists!

So I'm really lost now...Any idea?

Sam
 
Hi Rick

Yes the code is in the UserForm's code window. (i.e. I've double checked by
right-clicking on the form and select View Code. The UserForm's code window
then opens).

There is no "UserForm" in the lefthand side object dropdown for me to select
from so I don't think it's my typo either.

Why is the UserForm not recognized by Excel now, but it was before?

Sam
 
Since that situation should not exist, it sounds to me like your file may be
corrupted. Before trying what I am about to suggest, wait to see what others
say about your problem (they may actually have a good answer for you). Okay,
you have been warned.

I'm not sure if this will work or not, but what I would do is copy all the
code from the UserForm and store it in a Notepad text file, then I would
close the UserForm, then close Excel (maybe reboot the computer just in
case), restart Excel, add a UserForm and copy all the code you saved back
into its code window. Hopefully Excel won't *insist* that the UserForm
already exists and everything will be straightened out.

Rick
 
If you add another userform to the same workbook's project, do you see
everything ok?

I've seen situations where worksheets seem to have ghosts inside the VBE. The
worksheet is deleted, but it looks like it's still there in the VBE.

I've never seen this with userforms, though.
 
Now that I think about this, I'm not sure I remembered correctly.

Sometimes, if you close a workbook, that workbook's project looks like it's
still open inside the VBE.
 
I add another userform as you said, and "UserForm" appears in the righthand
side dropdown of the new userform's code window alright.

However, the event procudures of all controls in the old userform still
works fine. It's only the old userform that cannot be recognized in the VBE.

I wish there is a solution to this problem, as the last thing I want to do
is to retrieve from backup and re-do all the changes I've made...
 
I add another userform as you said, and "UserForm" appears in the righthand
side dropdown of the new userform's code window alright.

However, the event procudures of all controls in the old userform still
works fine. It's only the old userform that cannot be recognized in the VBE.

I wish there is a solution to this problem, as the last thing I want to do
is to retrieve from backup and re-do all the changes I've made...

Here's what I do when things get whacky

http://www.appspro.com/Utilities/CodeCleaner.htm
 
Hi Dick

Thanks for your suggestion, but unfortunately the problem doesn't go away
after running your Clean Project tool (UserForm itself is still not
recognized in VBE)..sigh...
 
If you want to send the workbook to me I can take a look.


--
Tim Zych
www.higherdata.com
Compare data in Excel and find differences with Workbook Compare
A free, powerful, flexible Excel utility
Now with Table Compare for quick table comparisons
 
Another thing to try against a copy of the troublesome workbook.

Start a new workbook (just a temporary workbook).
Open a copy of that troublesome workbook.

Go into the VBE.

Show the project explorer (ctrl-r if it isn't visible)

Drag the userform from the troublesome workbook project to the temporary
workbook project.

Does it work ok there?

If yes, try deleting the old userform in the troublesome workbook project.

Drag the userform from the temporary workbook project back to the original
workbook project.

Does it work ok there?

If yes, save the copy and use that instead.



Sam said:
I add another userform as you said, and "UserForm" appears in the righthand
side dropdown of the new userform's code window alright.

However, the event procudures of all controls in the old userform still
works fine. It's only the old userform that cannot be recognized in the VBE.

I wish there is a solution to this problem, as the last thing I want to do
is to retrieve from backup and re-do all the changes I've made...
 
Yes, that worked! Thanks!


Dave Peterson said:
Another thing to try against a copy of the troublesome workbook.

Start a new workbook (just a temporary workbook).
Open a copy of that troublesome workbook.

Go into the VBE.

Show the project explorer (ctrl-r if it isn't visible)

Drag the userform from the troublesome workbook project to the temporary
workbook project.

Does it work ok there?

If yes, try deleting the old userform in the troublesome workbook project.

Drag the userform from the temporary workbook project back to the original
workbook project.

Does it work ok there?

If yes, save the copy and use that instead.
 
Hi Tim

I saw Dave Peterson's reply below while getting the workbook ready to send
to you.
So I tried his suggestion and it solves the problem!

But thanks for your kind offer to help :-)

Sam
 
It doesn't explain what went wrong, but glad it worked.

If I were you, I'd keep a backup of that file--just in case something else
strange starts happening. You may be able to retrieve stuff from the backup if
you need to.

Sam said:
Yes, that worked! Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top