This code crashes excel (unless the VBA editor is open)

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
Good day,

I have the following code that was crashing my excel when it executed. Oddly enough (and by accident), I discovered that when the VBA editor is open, the code runs fine. So I know how it's happening but not why it's happening.
Any thoughts to why this is happening and perhaps suggestions to replace the code with something more robust?

VBA Code:
Dim UForm As Object

For Each UForm In VBA.UserForms
    If UForm.Name = "UserGUI" Then
        Exit Sub
    End If
Next UForm
 

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
Oddly enough (and by accident), I discovered that when the VBA editor is open, the code runs fine.
unfortunately that makes no sense. doesn't look like there's anything wrong with the code, to me. the only thing that might make a difference, which if it did, would make even less sense than this whole situation of your yours, would be changing:
Code:
Dim UForm As Object
to this:
Code:
Dim UForm As userform
you know, I've been scolded on other forums for bashing microsoft products, but unfortunately they are well known for crashing without reason. This could just be a case where you're working with a terrible application. just one man's opinion....
 
Upvote 0
Anyone who thinks Excel is a terrible application, clearly doesn't know how to use it. ;)
 
Upvote 0
Anyone who thinks Excel is a terrible application, clearly doesn't know how to use it. ;)
it was just an opinion, Rory! somehow I knew one of you guys would throw fire at me for that one! :)
 
Upvote 0
As was mine, hence the wink. :) (Although if you actually do think that Excel is just terrible, you're clearly delusional...)
 
Upvote 0
As was mine, hence the wink. :) (Although if you actually do think that Excel is just terrible, you're clearly delusional...)
let's not hijack this thread...i'll send you a PM.
 
Upvote 0
Take it outside!!! hahaha.

Anyhow, if you change as suggested (i.e. Dim UForm as Userform), apparently you cannot use UForm.Name as the that property does not exist?
 
Upvote 0
You'd have to use Typename(UForm) instead of UForm.Name
 
Upvote 0
I'm not sure what to tell you, Rawlins. But to quote those most famous words spoken by so many MS Access "professionals":
try reinstalling office
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

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