Show a form on all worksheets in an Excel file - excel

I am writing a little generator script (using Excel VBA) to generate a bunch of source code, given various input from users.
Currently I have one 'generator control' worksheet that provides access to the generation scripting tools. Here there is a button that pops up a little form with various generation options.
Each portion of source code also gets its own worksheet for generation purposes. So, I essentially have one worksheet for generation commands and perhaps 10-20 that are for source code parameters.
What I would like to do is somehow take my popup form and embed it within each other worksheet...make it 'always visible' in the corner or something like that.
Each source code worksheet is generated programmatically as well...I'd assume that I could replicate my popup button for each worksheet, but I'd rather have this form always visible.
Is something like this possible?

Rather than putting it on the worksheet, could you not have a toolbar button that simply pops up a dialog? (In other words, your user interface is a UserForm rather than a set of worksheet controls).

Related

Excel VBA Slow Opening

We have an excel workbook (xlsm) which has an embedded VBA code, which looks up the distance between two points using the getgoogledistance module.
Since we have added this to the workbook, it take a very long time to open sometimes in excess of 10 minutes..
I suspect on opening the workbook, it is trying to update all of the entries, hence why it is slow to open.
Is there a way in which I could add a button to the worksheet and rather than on 'open' update the necessary cells, when this button is clicked it updated all the cells?
Yes, you need to go to the options, then customize menu and from the list on the right, check the Developer menu.
Back to Excel, you'll be able to add controls such as push buttons and attach macros to them.

Adding a form control within module VBA

I've tried doing multiple searches, but may be wording incorrectly giving me info that doesn't apply.
I have a macro that parses through data, creates a new workbook and within that, a new worksheet. I want to be able to throw a form control or some sort of option for the user to add more data after the fact. Follow a similar example below to get a better understanding.
Say I have a workbook that I call "analyzer" and takes some input, formats it and also adds a summary tab. For instance, I'm a business and have all transactions made in my small store for a given month in a spreadsheet, .txt file etc. This is the input that "analyzer" takes in and formats.
"Analyzer" has a form control button on it and when you click it, it pops open a dialog box for you to select whatever months you want to analyze. Let's say its March. When I click on that button, I select January and February, it creates a new workbook, we'll call "Month_eval", formats each month in it's own worksheet and then adds a summary worksheet at the end for a "quick glance" view. Now I have this workbook, "Monthly_eval" that has three worksheets, Jan, Feb and Summary, but no real easy way to add say March or any additional months and append them to it or the summary worksheet.
What I would like to is add a form control button to the "summary" tab/worksheet to basically analyze more months of data and append to "Month_eval". The problem is this doesn't exist until I run the "Analyzer" workbook. I can't figure out how to phrase/search this to get relevant results.
I think I should be able to get it from there by assigning a procedure to the button click.
I apologize if this is asked multiple times. If there is something relevant or almost identical, please post and I'll close the thread.
So from data in WBX you want to create a new workbook WBY with N worksheets containing monthly analysis, and this WBY will have the functionality to append additional data from WBX?
I think maybe you will need to create a class for this WBY.
Why not have a Summary workbook (SWB) and an analysis workbook (AWB). When you want to analyse the data you just export it from SWB to AWB and do your formulas and view it, instead of generating a new workbook everytime?

Excel VBA - Multiple buttons pointing to same event

I am currently working on some excel document to automate it as much as possible.
For this I have to add the same button (let's call it an Erase All button for example) in each of the sheets.
Till here is OK. I have added it and all works fine. The problem is that the onClick event code is replicated in all the different sheets as a new Microsoft Excel Object code. What I would like is all the buttons to point to a single Module so I dont have to replicate code anywhere.
I come from a .Net environment and I know that VBA may have some restrictions or different usage but wondering whether I can avoid the onClick event in every sheet and put this onClick on a single generic module.
As a workaround I added my functionality as a SUB in the module and I call it from each of the different onClick events but if it is possible to directly clean all the sheet-specific code then it would be great :)
Any clue on that?
Hope is enough clear but in case need some more description please let me know and will try to add some graph/pic
Thanks a lot in advance!!
You can assign the same macro to each of the buttons. (Just right click on the button and 'assign macro')
As long as you designate the ActiveWorksheet as the sheet to process within the macro, this should be fine.
Alternatively you could instead create a non-modal userform with the required generic buttons which then has code to work on the active worksheet when pressed

Most User Friendly Way to use a VBA EXCEL Userform?

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

events and macros in excel vba not linking

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.

Resources