Clicking away from userform open text box VBA Excel - vba

I am not very good with userforms so hopefully this is an easy question.
I have a userform in a spreadsheet that opens with
UserForm1.Show False
To ensure excel can still be used while it is open. What I would like to happen is that whenever you click away from (but not close) the userform a text box is opened asking if you want to maintain the edited values or not. I can't figure out how to initiate more code when the userform is no long the point of interest. Usually items on userforms have enter and exit which I believe would do what I need but I can't find the equivalent for the actual userform.
Any advice would be appreciated.

To allow a user to enter values into excel while a form is visible, you will need to update the ShowModal property on the userform to false.
Or as you are showing the userform, you can show it vbModeless.
UserForm.Show vbModeless

Related

How do I make a userform appear on demand in Microsoft Word?

I can make it popup on opening the document, but what if I close the userform and want to it to show up again in the same document? I know in excel you can add a button onto a worksheet directly and make it show the userform on click, but this button is unavailable for microsoft Word. Is there a solution besides initiating the script by hand?
To display a VBA userform, you can trigger it from a macrobutton field, from a form field, from a shape, from a QAT button or from an ActiveX button. There are probably a couple of other methods I'm not remembering at the moment. Each is a little different in the exact steps, but all will run the command:
UserFormName.Show

Prevent excel from closing when closing userform

I hope you can help me with this issue, I couldn't find any answer nor on google nor here. So here's the point:
I have to userforms. One of them opens on Worksheet_Open. In the Background I can still see the worksheet and the excel application. But when I click outside of the userform or close it, the application window disapears too. But in the open processes I can still see excel open.
My intention is to have the Excel window always open (in the background) so that when I close the UserForm the Excel Tables will be visible.
What do I have to code for that? To hide the userform didn't work for me...
Thanks in advance.
Hi there if you want to use both excel and your Userform at the same time then go to your Userform property and make ShowModal = False

Hide userform in VBA in order to work with data

I have a following problem. I would like to hide a userform in order to work with data in worksheet.
I would like to enable user to get back to application.
So I thought if there is a possibility to move userform down on the screen and activate workbook.
Afterwards the user could drag userform back in the middle of the screen and work with it again.
Does anyone have an experience with something like that?
You can use me.hide to hide userform, retaining all values entered into the form. Use me.show to bring back the userform to the screen.
This is different from unload me, which unload the userform from memory, destroying all values entered. Calling the form again will start the form a new.
If you want the form to be still visible and allow user to interact with worksheet behind, then set the ShowModal property to False.. The default is True.

Run macro by clicking away from any ActiveX textbox in a document

I'm looking for a VBA script that will run whenever I click away from any of ActiveX textboxes in the document. Another alternative would be to have it run whenever I click on any textbox (without clicking away).
How can it be done without assigning subs to each textbox individually?
Double click on your textbox and it will bring up the default method for that textbox, which in my testing is Textbox1_Change(). This method will run every time you type anything into the textbox.
You see two dropdown boxes at the top of the vba editor. Drop down on the one on the right and you'll see all the other available methods for the textbox, one of which is LostFocus which I reckon will suit your purposes. Clicking on that creates a sub that will execute every time the textbox loses focus. See how you go with that. Cheers

Excel AddIn - Keeping windows form always visible while w/in Excel

First of all, thank you for your time and assistance in reviewing this!...
I'm trying to upgrade an Excel VBA workbook to a VSTO Excel Add-in in VB.NET using VS 2010. In the original (i.e.- VBA) version I have a modeless UserForm (called frmMain) that floats on top and is visible at all times while the user is still within the Excel application, but is not visible if the user moves to another window outside of Excel.
For example, within Excel the user can click on any worksheet tab, select any cell, etc. and the UserForm is still visible. This is exactly how I'd like it.
The problem is, that in the new VSTO add-in, I can not get the Windows form to mimic this same behavior.
I use frmMain.Show() to show the form as a modeless form, but the moment the user clicks an Excel worksheet (i.e.- activates a worksheet) the form becomes hidden behind the worksheet.
I can manually Alt-Tab to bring the form back into view, but I need it to always remain in view - floating on top of the Excel worksheets so long as the user hasn't left the Excel application.
I tried various things, including setting the form to TopMost, however, that causes the form to be TopMost everywhere - including outside of Excel. Worse than that, if the user does anything that would normally result in Excel's launching a dialog box (e.g.- closing an open workbook, raising the alert "Do you want to save the changes...") the alert dialog box itself is hidden and inaccessible behind the frmMain form (since the frmMain is TopMost).
How can I get my form to behave in the desired way (i.e.- the same way it did in VBA)?
Thanks!!!
Rob
You should take a look at Custom Task Panes which can be docked or floated within the Excel application. You could also look into the COM interfaces for a lower level connection (see related SO Post) - although Task Panes are really what this type of behavior was intended for.
This method might work (worked for me):
Create a worksheet_selectionChange event handler inside your form class
Put these lines in this event handler:
Dim FormHandle As IntPtr = Me.Handle
Me.Visible = False
Me.Show(NativeWindow.FromHandle(FormHandle))