VBA form not being recognised by the code

Chris_Hed

New Member
Joined
Feb 2, 2025
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I've searched this forum and others without success solving this weird problem. It might be an Excel bug, but I'm hoping it's just something I'm doing wrong.

My fairly basic spreadsheet has two userforms. One works perfectly well but the other won't even load. It did when I first created it but now isn't recognised by the code.

Observed behaviour:
  • The form appears to be correct in design and code windows (VBA editor)
  • Form name appears to be recognised in the code because capitalisation "errors" are automatically corrected.
  • Load(userform2) throws error 424 (object required). When hovering over the line in debug mode, it shows userform2 = <Object variable or With block variable not set>
  • Set Frm = userform2 throws error 424 (object required). When hovering over the line in debug mode, it shows userform2 = <Object variable or With block variable not set>
  • Dim Frm as New userform2 throws error 424 as well.
Things I've tried:
  • exporting then importing the userform
  • saving the excel sheet as a new file
  • disabling then re-enabling the macros
  • removing and reauthorising trusted locations and documents.
  • repairing Office 365 (short and long versions)
I'm really running out of ideas on this one so all suggestions welcome :-)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Sounds like you have a variable named userform2 within your project. Find that variable and change its name.

Also, if the following works, it means it is probably the above variable naming issue :
VBA Code:
VBA.UserForms.Add("UserForm2").Show
 
Upvote 0
Thanks for taking the time to reply.

I should have also listed that I tried renaming the userform as well without success. I'm certain that there is no variable by any of those names in the project (the form name is actually frm_NewIncident, so pretty hard to use without noticing).

I tried the code you suggested and got the same error 424 (object required) highlighting that line of code. In debu mode there was no mouseover text.
 
Upvote 0
OK, more troubleshooting and a little more info.

When importing the exported file into a brand new workbook, the behaviour followed it. The other (working) form imported and worked just fine.

It seems to be something specific to the form and I might just need to accept remaking it from scratch :(
 
Upvote 0
Try "Dimming" the form before using "SET" :

  • VBA Code:
    Dim Frm as New userform2 throws error 424 as well.
    [*]
    
    [*]Set Frm = userform2 throws error 424 (object required). When hovering over the line in debug mode, it shows userform2 = <Object variable or With block variable not set>
    [*]
    
    [*]Load(userform2) throws error 424 (object required). When hovering over the line in debug mode, it shows userform2 = <Object variable or With block variable not set>

As a rule I always "Show" a userform rather than "Load" it : "UserForm2.Show"
 
Upvote 0
Post your workbook to a download site, then provide the link to download here.
 
Upvote 0
Thanks Logit,

I did try that but it threw the error at the step of dimming before it even got to the set command.

Load and show do different things, so aren't really alternatives to each other.
 
Upvote 0
and figure out how
After anonymizing your personal information, go to a free file hosting site like www.dropbox.com or www.box.com (the personal version is free), create an account, upload your file, there will be an option to share the file and then to create a link, create the link and then copy/paste the link it creates directly in the thread.
 
Upvote 0

Forum statistics

Threads
1,226,460
Messages
6,191,164
Members
453,643
Latest member
adamb83

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