UserForm1.Show : “File Not Found”

OldRookie

New Member
Joined
Nov 12, 2020
Messages
19
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
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

EXCEL MAX

Board Regular
Joined
Nov 11, 2020
Messages
110
Office Version
  1. 2007
Platform
  1. Windows
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.
 

OldRookie

New Member
Joined
Nov 12, 2020
Messages
19
Office Version
  1. 2013
Platform
  1. Windows
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
 

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,576
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,921
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.:)
 

OldRookie

New Member
Joined
Nov 12, 2020
Messages
19
Office Version
  1. 2013
Platform
  1. Windows
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,921
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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.
 

EXCEL MAX

Board Regular
Joined
Nov 11, 2020
Messages
110
Office Version
  1. 2007
Platform
  1. Windows
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)
 

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,576
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.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,652
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Do you have code in the Userform_Initialize or Userform_Activate events?
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,114,204
Messages
5,546,539
Members
410,745
Latest member
citrictango
Top