So I have programmed several userform with several user inputs(text boxes, check boxes, etc.) Now how can I use them outside of excel?
Currently I have to:
Open up the spreadsheet
Enable macros
Go to Developer Tab, View Code
Then find the right userform and run it or type F5.
Is there a more user-friendly way to run the userform? Its for testers who don't know vba or excel programming.
Thanks!
Yes, absolutely. You could create a button named after the form in question, and to that button assign the following macro:
Sub btn1()
frm1.Show
End sub
That's it! Of course, change the names according to what you have :)
I also reccomend having a button to close the form on the form itself.
OF COURSE this still uses Excel. If you want to use them on their own you could have something like this guy did: How to Open only UserForm of an excel macro from batch file
Related
Is it possible to preview print a user from in vba excel or print the user form to a place in a worksheet?
I already know this
UserForm1.PrintForm
Here is the answer.
It is not possible to display a Print Preview of a userform using only VBA.
It is possible to do so using a series of Wind32 APIs, as the userform is a Window. However, this is not trivial and requires a lot of code.
I have developed a VBA userform interface that allows the user to input values, have it calculate results, and then print them out into the worksheet. I am wondering if there is any possible way that I can have a button on the excel ribbon, say under the "Data" tab for instance, that would elicit the userform interface to open.
Currently the only way I can use the interface is by Developer>>Visual Basic>>Clicking on Userform>>F5. This also limits the userform in that it can only be used in one particular workbook as opposed to many. Or if it was somehow possible, to make it an add-in instead.
Any help is greatly appreciated!
The easiest way to add custom tab and/or button to Ribbon is to use Custom UI Editor Tool for MS Office Ribbon. Follow the links provided in comments to your question too. There you'll find many useful information.
I have an existing excel sheet which has some macros written in modules. The sheet has various button kind of controls (check 1st scenario), but not a button (as I could not see the button control selected in even in design mode, as it is in the case of 2nd scenario).
So I was wondering what control it is and how can I link it with macros defined?? Also the coding is in modules and not in sheet, why??
I even tried to link a macro with the button created in scenario 2, but it didnt work out. I am new to excel vba, pls suggest some solution.
Also I would like to know more about macro, like why do we need a macro if we can write event based code on button click??
First off "Macro" is the generic term excel uses for VBA code. VBA is the language you are writing in when you "writing a macro". You can write VBA in a subroutine as part of the sheet object, workbook object, an independent module, class, or form. Events are part of a workbook, worksheet, or form object that can trigger code that is contained within the event's VBA routine.
Your Scenario 1 looks like maybe those are shapes drawn on the worksheet. Shapes can have "macros" assigned to them. You right click on the shape, and go to "Assign Macro". It will write the event subroutine in that worksheet's code in your Visual Basic Editor (VBE). You can then write the code inside that subroutine that was generated for you which may call other subroutines or functions that you have written in a module.
You can also tie subroutines, regardless of which object they are written in (module, worksheet, workbook) to a CommandButton, like in your second scenario. This particular button you added is an ActiveX control type button. They tend to be a bit more complicated. You should probably just go with a normal "Form Control" button as it will ask you, after you draw it, which SubRoutine you want to attach it to.
So to answer you question: Go to Developer>>Insert>>Form Control>>Button and draw it on. Then point it to your VBA subroutine that has the code you want to execute when you hit the button. Nice and simple.
When I user the user form, I have to:
1) Alt + F11
2) Choose the Form
3) Run
4) Close the Form
5) Go back to Excel
Excel will not allow me to do anything if the form is not closed. Is there anyway to let me put a little icon on ribbon? And keep the user form appear while I am working with Excel?
You've got two parts to your question:
Adding an icon to the ribbon: Do you want the macro to be available for all spreadsheets?
If so, follow this guide to save your macro as an Excel Add-in, and then attach it to the ribbon.
If you only need it in the current spreadsheet, you could simplify things by adding a button to the spreadsheet which activates the macro (use this guide), or you could use a shortcut key to invoke the macro directly (use this guide, Assigning a shortcut to an existing macro section)
Keeping the dialog open: One of the properties of the UserForm is ShowModal; you can simply set that to false. Alternatively, as per the other answer, you can open it with MyForm.Show vbModeless.
Note that the properties of the form also allow you to provide a specific screen position too, so that the form isn't in the way while you're working: change StartUpPosition to 0 - Manual, and provide a value for Top and Left.
You don't need to do that :) You can simply launch the form in modeless mode to keep it open and work with the Excel file at the same time
Try this to launch the userform.
Sub Sample()
Userform1.Show vbModeless
End Sub
I think you should have to create another module and call the userform in that module. After that just put that macro on the ribbon.It may help you.....
How can I add an input form in an Excel sheet. I want to insert values into an Excel cell using the form.
ALT+F11 starts the VBA editor in Excel. In there you can create UserForms (Insert | UserForm) which you can bind into their own modules or attach to worksheets.
I suggest you look at the Excel help or MSDN for details of what you can do with UserForms. There are also a lot of VBA tutorials on the web for exactly this sort of thing. Google is your friend.
HTH
There is a quick and dirty method of creating simple forms in Excel. No VBA is required.
First, create a table with the basic format that you want.
E.g.
A B C
1 Name Age Favourite Animal
2 Jane 11 Horse
Select the range, and then select Data | Form. (This is in Excel 2003.)
It will open up a simple form that allows navigation, creation, deletion, and searching.
#Oddthinking,
Cool trick. Never knew it existed. I had to do a little looking, but you can do it in Excel 2007 as well.
Click the Office button, select Excel Options, go to the Customize tab
Select 'Commands Not in the Ribbon' from the 'Choose commands from' drop down
Find 'Form' in the list and click Add, then click OK
At this point, the Forms command will show up on the Quick Access toolbar, next to the Save and Undo/Redo icons.
You have to activate the form toolbar.
Of course, IIRC, the form must be handled by VBA code.