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, 10 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
-
How to get Microsoft Defender to honor Group Policy Setting (Awaiting moderation)
by
Ralph
1 hour, 22 minutes ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
2 hours, 1 minute ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
3 hours, 7 minutes ago -
Disengage Bitlocker
by
CWBillow
4 hours, 31 minutes ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
5 hours, 7 minutes ago -
New Win 11 Pro Geekom Setup questions
by
Deo
6 hours, 51 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
12 hours, 22 minutes ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
12 hours, 24 minutes ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
16 hours, 19 minutes ago -
New PC transfer program recommendations?
by
DaveBoston
6 hours, 39 minutes ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
20 hours, 23 minutes ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
20 hours, 25 minutes ago -
Best tools for upgrading a Windows 10 to an 11
by
Susan Bradley
8 hours, 44 minutes ago -
The end of Windows 10 is approaching, consider Linux and LibreOffice
by
Alex5723
6 hours, 6 minutes ago -
Extended Windows Built-in Disk Cleanup Utility
by
bbearren
18 hours, 34 minutes ago -
Win 11 24H2 June 2025 Update breaks WIFI
by
dportenlanger
1 day, 15 hours ago -
Update from WinPro 10 v. 1511 on T460p?
by
CatoRenasci
13 hours, 17 minutes ago -
System Restore and Updates Paused
by
veteran
1 day, 17 hours ago -
Windows 10/11 clock app
by
Kathy Stevens
1 day, 5 hours ago -
Turn off right-click draw
by
Charles Billow
1 day, 21 hours ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
2 days ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
18 hours, 32 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
2 days, 2 hours ago -
Suggestions for New All in One Printer and a Photo Printer Windows 10
by
Win7and10
1 day, 5 hours ago -
Purchasing New Printer. Uninstall old Printer Software First?
by
Win7and10
2 days, 8 hours ago -
KB5060842 Issue (Minor)
by
AC641
20 hours, 23 minutes ago -
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
2 days, 15 hours ago -
24H2 may not be offered June updates
by
Susan Bradley
1 day, 7 hours ago -
Acronis : Tracking Chaos RAT’s evolution (Windows, Linux)
by
Alex5723
3 days, 3 hours ago -
June 2025 updates are out
by
Susan Bradley
9 hours, 23 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.