UserForm1.Show : “File Not Found”

OldRookie

New Member
Joined
Nov 12, 2020
Messages
36
Office Version
  1. 2013
Platform
  1. Windows
I have some VBA code that works. I’m trying to speed up user data entry by using a Userform. It’s my first Userform and don’t know why I’m getting a “File Not Found” error message when I try to execute a “Userform1.show” command buried in my calling macro in Module1.

Userform1 has 5 option buttons and 2 command buttons. The idea is for the option buttons to assign an integer number to a public declared integer variable in Module1 depending on which button is chosen. Once chosen, the coding associated with an “OK” command button determines which option button was selected and assigns the appropriate value to the public variable in Module1. The remaining “Cancel” command button simple executes “Unload Userform1”.

After I receive the “File Not Found” error message and select “OK”, I receive a “Can’t Load or Unload This Object” error message. Upon debugging, I find the “UserForm1. Show” command highlighted in yellow. When I try to save the file, I get the “File Not Found” error message again. Selecting “OK” there numerous times to get out of an endless error loop triggers all kinds of other error messages. The long and short of it is, I can’t save this spreadsheet with all my work in it. I realize without posting lots of my code it’s hard to determine exactly what’s wrong. Some general suggestions on what to look for would be a good place to start. Any help would be greatly appreciated.

Thank you,
OldRookie
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hello Rokie,
as you says "Iit’s hard to determine exactly what’s wrong".
Try to declare variables in the moudule as global instead public.
Check, maybe your program close active window before end procedure.
 
Upvote 0
Thank you for your reply! I changed my public declaration to global and that didn’t fix the problem. I don’t understand what to look for in regards to your second suggestion: “maybe your program close active window before end procedure.” Could you please elaborate more?

As a further diagnostic, every time my calling macro encounters “UserForm1.Show”, it adds:
Private Sub UserForm_Click()
End Sub
to the UserForm macro codes (after I’ve deleted these statements). The coding for my control buttons does not reside inside this macro. Should they be nested like this?:
Private Sub UserForm_Click()
Private Sub OKButton_Click()
...
End Sub
Private Sub CancelButton_Click()
...
End Sub
End Sub

Perhaps it’s faulting on my reference to the option buttons. I’ve tried these two decision makers inside Private Sub OKButton_Click():
If count1=True Then....
End If

then I tried:

If count1 Then.....
End If
(where “count1” is the name of one of the option buttons). Neither fixed the problem.
Just so I can rule this out, what is the correct reference to option button selection in If-statements?

Again my apologies for vagueness. It would get quite lengthy and confusing to post all my code. Bombing at such a seemingly overarching level, leads me to believe it’s something structural (like my nesting question) and not something simple like a missing comma (although I realize that could be it...!). I only have one thin example to guide me through this.

Thank you,
OldRookie
 
Upvote 0
Hi OldRookie. A bit of Googling similar userform and file not found errors seems to indicate that you should check to make sure the userform is named correctly (ie. that U are suing the same name in code as what it's actual name is) That nested loop stuff makes no sense. U named your optionbutton Count1? If U did it would be something like...
Code:
 If Userform1.Count1 = True then
HTH. Dave
 
Upvote 0
OldRookie

You shouldn't be nesting things like that.

Can you post at least some of the code?

P.S. Remember to wrap it in code tags.:)
 
Upvote 0
Dave, Norie,
I wasn’t able to salvage my original UserForm so I started over again. It worked!.........sort of. This time I didn’t change the name of the UserForm from UserForm1>Test>UserForm1. Evidentially it doesn’t like that. I found an article on the Internet where the programmer had a similar problem and starting over solved their problem. I wondered about changing names offered by VBA when I did it. I suspect those in the know can, but that’s not me at this point.

I still don’t understand why VBA automatically creates:
Private Sub UserForm_Click()
End Sub
in the UserForm coding macros if I delete it. I don’t put anything in it..... When do you use that macro?

Execution in the calling macro in Module1 halts when it encounters UserForm1.Show. Then it executes the UserForm macros and returns control to the next command in Module1 immediately following the UserForm1.Show command. This is what I want, but the curious thing is, the rest of the program doesn’t work now and I don’t know why.

Norie,
Thank you for your interest in this problem. In regards to your post script: “ Remember to wrap it in code tags.” , are those comment statements? Please forgive me, this is my first UserForm and I’m self-taught in VBA. My VBA programming skills are adapted from early 1970’s FORTRAN & BASIC languages. As such, my coding is brute force by today’s standards. Posting my code would open a huge can of worms.

OldRookie
 
Upvote 0
Changing the name of a userform shouldn't cause any problems at all.

In fact I would recommend changing the name to something more descriptive than the generic UserFormX.

As for code tags, they are used to wrap code when you add it to a post here, it makes the code readable and easy to copy.
 
Upvote 0
After you run code and debug stop in the "Userform1.show",
do you have more workbooks opened in the same time ?
(Look in the Project Explorer at left side)
 
Upvote 0
OldRookie just to be sure U know (I didn't for quite some time), there is a difference between a userform name and a userform caption. If U select the userform in the design window and right click for properties you can see there are 2 seperate items (Name and Caption) that can be changed. If U changed the caption, U haven't changed the userform name. Not sure if this is relevent but I thought I'd throw it out there. HTH. Dave
ps. "I still don’t understand why VBA automatically creates:"
Code:
Private Sub UserForm_Click()
End Sub
XL is just being "Helpful with it's "intellisence" :)
U can just delete that stuff that U don't need.
 
Upvote 0
Do you have code in the Userform_Initialize or Userform_Activate events?
 
Upvote 0
Solution

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top