i have a user form (vba) that inputs data into the spreedsheet. but when i exit out of the userform and go into the spreedsheet there is no way for me to bring back up the userform. I have to close out of what i’m doing and reopen it. there has got to be a better way of doing this?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
going from excel spreedsheet to vba userform
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » going from excel spreedsheet to vba userform
- This topic has 14 replies, 7 voices, and was last updated 14 years, 9 months ago.
AuthorTopicWSvanoskyj
AskWoody LoungerJuly 30, 2010 at 3:32 pm #470697Viewing 10 reply threadsAuthorReplies-
WSAndrewKKWalker
AskWoody LoungerJuly 30, 2010 at 6:59 pm #1237010Depends where the Userform is and if it is still available to use.
Is it part of the same spreadsheet or is it in another one.If it is in the same workbook, then a button with something like
NameOfUserForm.Show as its click event would do
Best way is to create a Manual Macro in a Module
with that code in it and then assign it to a button on the sheet.
e.gCode:Sub OpenUserForm NameOfUserForm.Show End Sub
Cannot help more than that because I do not know from where the form is being called.
-
WStrevithick
AskWoody LoungerJuly 30, 2010 at 10:13 pm #1237022Andrew is right on about using show. To add a thought to that, instead of closing the form as you apparently are now when you think you’re through with it, use hide instead. As Andrew said you can then click on a button to show it again and it should remain populated with the data it had when you hid it.
-
WSrory
AskWoody LoungerAugust 2, 2010 at 7:16 am #1237177FYI, you should not really use the default userform instance – it’s a class and should be handled as one. So rather than:
Code:Userform1.Show
you should really use something like:
Code:Dim frm as Userform1 Set frm = New Userform1 frm.show
For a casual one line bit of code, you can get away with using the former syntax, but for anything more complicated, it’s better to do things properly, not least because it will make it easier to debug.
-
RetiredGeek
AskWoody_MVPAugust 8, 2010 at 7:13 am #1238220FYI, you should not really use the default userform instance – it’s a class and should be handled as one.
For a casual one line bit of code, you can get away with using the former syntax, but for anything more complicated, it’s better to do things properly, not least because it will make it easier to debug.Rory,
This intrigued me. I did a little testing and I now understand that a defined form is a Class a useful piece of information. So if I have a form named ufCarMenu I should:
Code:Sub ShowMenu() Dim frm as ufCarMenu Set frm = New ufCarMenu frm.show End Sub
This would also allow me to have a second copy {instance} of the form open as follows:
Code:Sub ShowMenu() Dim frm2 as ufCarMenu Set frm2 = New ufCarMenu frm.show2 End Sub
Correct?
The above is just for clarification for both myself and others who might have been confused in thinking that UserForm1 was a data type vs the default name for a newly created form {which should always be renamed since we’re discussing good coding practices here}.
Would it also be good coding practice to clear the object frm, i.e. Set frm = Nothing, upon closing the form?
What I still don’t understand is how this syntax assists in debugging? Could you please elaborate.
-
-
WSmotivated
AskWoody Lounger -
WSrory
AskWoody Lounger -
WSrory
AskWoody LoungerAugust 8, 2010 at 8:20 am #1238226Correct. In fact, Userform1 is a class, an interface and the name of a default instance of that class. (strictly speaking, when you declare the variable As Userform1, you are saying that it implements the Userform1 interface, not that it necessarily is a Userform1 instance, but that’s not really the point here!)
Typical (simplified) example of the sort of problem I see frequently in the forums and newsgroups:
Code that loads and uses the form:Code:Userform1.Caption = "my new form caption" Userform1.Show msgbox userform1.caption
but the form itself either uses Unload rather than Hide, or the user clicks the X to close it, so the message actually says “Userform1” and the programmer can’t figure out why. It is because the use of Userform1.Caption actually silently creates a new instance of the form. If you use a variable, you will get an error which lets you know your form has been destroyed, and you can then work out why. On that subject, when you use variables, you should ensure that the user can only hide the form, not unload it – you do that in the calling code by setting the variable equal to Nothing.
Does that make sense?
-
RetiredGeek
AskWoody_MVPAugust 8, 2010 at 10:40 am #1238243you should ensure that the user can only hide the form, not unload it – you do that in the calling code by setting the variable equal to Nothing.
Does that make sense?
Rory,
Yes it does make very good sense. A follow on question from the quote above. Why not allow the user to unload the form? Is this for efficiency or some other reason? If it is for efficiency of re-displaying the form would it them be acceptable {i.e. good coding practice} to allow the user to unload a form that is only used in the initialization of the setup, e.g. selecting a file or entering a password?
-
-
WSrory
AskWoody LoungerAugust 8, 2010 at 11:31 am #1238251Two reasons really:
1. Your code created the form, therefore your code should destroy it.
2. If you need to use any of the information from the form in your code after showing it, you need to keep it loaded. Even if you don’t currently use the information, you may change the program later, and it’s simpler if you have already ensured that your code is the only place it can be unloaded.Obviously this is just stuff that I consider to be “best practice” – others may have different opinions, and for quick and dirty apps, there may be no need to go to all that trouble (though I tend to find that even those apps tend to take on a life of their own, far beyond my original intentions!
-
RetiredGeek
AskWoody_MVPAugust 8, 2010 at 8:13 pm #1238299(though I tend to find that even those apps tend to take on a life of their own, far beyond my original intentions!
Rory,
I’ll second that! I’ve built one-ups for quick and dirty answers that lasted for years while I was working. It’s always best to plan for the future because it always comes!
Thanks for sharing your insights I really appreciate it as I’m a self taught VBA guy and always looking for a “better way”.
-
-
zeddy
AskWoody_MVP -
RetiredGeek
AskWoody_MVPAugust 11, 2010 at 12:53 pm #1238632Yes, just the fingers lagging behind the cranium!
-
RetiredGeek
AskWoody_MVPAugust 15, 2010 at 8:03 pm #1239410Hello Again,
To continue this discussion of Userform as Class…
I was modifying one of my projects to use this coding technique when I noticed a significant difference in this technique.
The first time you show the form the UserForm_Initialize event is fired. However, when you Me.Hide the form then once again do a frm.Show the UserForm_Intitialize event is NOT fired!I had to change to the UserForm_Activate event to get my form setup code to run every time the form is shown. Is this how it should be or did I do something else wrong?
Update: Also…the userform retains it’s data so you need to clear the fields before the next use, which can be done in the UserForm_Initialize event handler.
-
WSrory
AskWoody LoungerAugust 16, 2010 at 1:25 am #1239430That’s how it should be and is the same whichever syntax you use. The Initialize event occurs when the form instance is created and loaded into memory. When you show and hide the form, the activate and deactivate events are triggered. All you need to is set the form variable to nothing and reinitialise it to create a new “fresh” instance.
Viewing 10 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
43 seconds ago -
Sometimes I wonder about these bots
by
Susan Bradley
6 hours, 53 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
12 hours, 57 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
13 hours, 57 minutes ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
13 hours, 23 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
9 hours, 53 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
16 hours, 39 minutes ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
16 hours, 41 minutes ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
5 hours, 15 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
1 day ago -
0Patch, where to begin
by
cassel23
18 hours, 50 minutes ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
1 day, 14 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
1 day, 2 hours ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
1 day, 22 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
1 day, 13 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
1 day, 1 hour ago -
Installer program can’t read my registry
by
Peobody
7 hours, 46 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
1 day, 11 hours ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
1 day, 19 hours ago -
False error message from eMClient
by
WSSebastian42
2 days, 10 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
2 days, 19 hours ago -
Office 2021 Perpetual for Mac
by
rebop2020
2 days, 20 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
7 hours, 2 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
2 days, 23 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
7 hours, 21 minutes ago -
Outdated Laptop
by
jdamkeene
3 days, 5 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
3 days, 10 hours ago -
Another big Microsoft layoff
by
Charlie
3 days, 10 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
12 hours, 34 minutes ago -
May 2025 updates are out
by
Susan Bradley
14 hours, 16 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.