Hide modeless form when all macros stop - vba

First of all I want to thank everyone who has helped me with answers here. You guys have been important in my development and for that you have my respect.
For the question: I want to create a form that displays the status for running multiple macros in sequence. For that i'm showing a form modelees so the macros continue running in the background.
The way I have it setup now, the form remains visible after macros are done.
Is there a way i can trigger the form to hide/unload when no macro is running?
Thanks,
Daniel

Just unload the form at the end of the last macro. I assume you have one calling sub which handles showing the form and calling the macros, so that is where I would also hide the progress form.

Related

Using Excel while macros are running

There are a half-dozen answers to this. "Open a second instance" "Have a pause" Etc. I'm not looking for that.
I'm looking for the user of the workbook to be able to manipulate the workbook while the macro is running. I've seen this working before, where the user could scroll around, change tabs, even add and remove data, all while the macro was running. Unfortunately, I couldn't get permission to look at the code (And committing CFAA violations ins't my cup of tea), so I have no idea how they did it.
How can you enable a user to edit the workbook as macros are running? For a specific example, I have Conway's Game of Life running. Users select cells to flip live/dead, then can run a macro to run the entire thing. I think it'd be nice for users to be able to change cells as the macro is running. (which is a second on select macro)
Thank you
Sorry just reread the question. I wouldn't expect the permutation to run for very long - not long enough to interrupt really.
But if it does, then the advice about using lots of DoEvents stands.
The other option is that you can use the OnTime event to have a "heartbeat"
VBA Macro On Timer style to run code every set number of seconds, i.e. 120 seconds
You can set the timer to say 3 seconds. Every time the OnTime event occurs you do one step of your permutation. In the three seconds in between they can edit.
Refactor your macro to use Events. In which case, you would have a series of event handlers (instead of one monolithic macro) to respond to various triggers. This is assuming that the macro is influenced by what the user is doing in the worksheet.
One way of (sort of) doing this is to use a Modeless Userform (UserForm.Show vbModeless)
The user form stays visible but the VBA stops running when the form is shown and the user can then interact with Excel. Then when the user clicks a button on the form the code behind the button starts running again.
So in reality the user is either interacting with Excel or interacting with the form ...

Close userform using myForm.Hide or Unload Me

Before I start let me give you the background. I am working on a VBA project with Excel and the computer I am using has limited resources (and I have been asked to do as light as possible for fast execution time).
In my project I open multiple userform at different times, to apply filters on my sheet for example.
As I just said resources are limited and I want to know if frmFilters.Hide is enough to close the userform or if there is a better way to do so ?
I've read about Unload Me but I'm not sure how it's working because I'll apply filters from my form and I need to keep them once the form is closed until the user totally close the Excel file.
Is there a situation where Unload Me is better than frmFilters.Hide ?
Regards,
Teasel
I found an interesting answer to my question I thought it would be useful to post it here.
Unload me
Unload me
Removes the form from the memory and stop the application if you do so on the main form of your project. Every modification that you did in your form will be lost.
Hide
myForm.Hide
Only hide the form. If you do so on the main form of your application, this will not end the program (the debug mode would still be running for example). Every modification that you do in your form will be kept for the next time you show your form.
Which one to use?
Depends of the situation I believe. In my project, my form was made to be open/close multiple times so I chose to only hide it to avoid having to allow memory for my form every time.

Progress Bar in Excel using VBA and userForms

so I've been looking and cant find anything on this, I hope someone can help.
what I am trying to do:
I want to create a progress bar for my excel workbook that I am making. in order to accomplish this I have created a user form with data fields that I can manipulate from outside of the userform. what I would like to do is to load the userform from inside a module and then from the same module update the userform as the module continues to run.
is there a way to do this?
currently when I use userForm1.Show it displays the userform, but the control never goes back to the calling module, and the code ends when reaching the End Sub for Private Sub userForm1_Activate()
any help would be appreciated.
thank you
You are opening the userform as a modal form. To return the control back to the calling module, you must open the userform modelessly:
UserForm1.Show vbModeless

Form Option Button Reset Macro

I am looking for a simple macro I could activate with a form control button that would clear all of the form control option buttons on my sheet.
I have lists of options for industrial part specifications, of which only one may be selected per section. However, once one is selected, the form control option button stays filled in. I previously circumvented this by using checkboxes, where if you click the box again it will remove the check mark. However once I learned that I was to create the form in such a way that only one option could be selected per section, (for ease of use in case a less computer minded person were to use it) it became clear that option buttons were the right way to go.
So I need a simple macro that I can activate with a button that will clear these option buttons all to blank, as if none were selected. I have looked and tried some strings of code, but none have worked so far. Perhaps I am missing something obvious or looking for the wrong thing, but I dont think I am.
I have checked the following pages and tried their code:
http://www.mrexcel.com/forum/excel-questions/689865-how-clear-all-checkboxes-option-buttons-list-boxes-form-3.html
Re-setting all option buttons at once
http://www.excel-easy.com/vba/examples/option-buttons.html
I feel like this should be simple. A VBA macro code that will reset the FORM CONTROL Option Buttons to blank (which I believe is the false state?). No need to worry about having specific ranges to clear; one button to reset the sheet will do perfectly.
Thanks in advance for any help.
Cycle through the Shapes collection:
Sub Reset()
For Each vCtrl In ActiveSheet.Shapes
vCtrl.DrawingObject.Value = False
Next
End Sub

Closing a Userform with Unload Me doesn't work

I need to close an Excel userform using VBA when a user has clicked a submit button and operations have been carried out.
How can I close a Userform from itself?
I have tried this but it returns a 361 error.
Unload Me
As specified by the top answer, I used the following in the code behind the button control.
Private Sub btnClose_Click()
Unload Me
End Sub
In doing so, it will not attempt to unload a control, but rather will unload the user form where the button control resides. The "Me" keyword refers to the user form object even when called from a control on the user form. If you are getting errors with this technique, there are a couple of possible reasons.
You could be entering the code in the wrong place (such as a
separate module)
You might be using an older version of Office. I'm using Office 2013. I've noticed that VBA changes over time.
From my experience, the use of the the DoCmd.... method is more specific to the macro features in MS Access, but not commonly used in Excel VBA.
Under normal (out of the box) conditions, the code above should work just fine.
Without seeing your full code, this is impossible to answer with any certainty. The error usually occurs when you are trying to unload a control rather than the form.
Make sure that you don't have the "me" in brackets.
Also if you can post the full code for the userform it would help massively.
Unload Me only works when its called from userform self. If you want to close a form from another module code (or userform), you need to use the Unload function + userformtoclose name.
I hope its helps
It should also be noted that if you have buttons grouped together on your user form that it can link it to a different button in the group despite the one you intended being clicked.