Prevent excel from closing when closing userform - vba

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

Related

Excel VBA add right-click button to addin

I am trying to make an Addin with Pivot right-click button.
All the macros are working in the addin perfectly on every workbook that I open.
The problem is that the right-click buttons don't appear in other workbooks - only in the one with the addin.
Screenshot
As you can see I have written the code in ThisWorkbook module, and the Subs are Private. - I guess that somewhere here is the problem.
Would be very grateful if somebody can help.
Ah, I found the problem.
Obviously, the first part of the code was preventing the buttons to appear in other workbooks.
Other than that, Temporary:=True. it should be False.

Clicking away from userform open text box VBA Excel

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

View Code When Modal Dialog Is Open In Excel

This may be a stupid question, but I feel like I'm in a pickle. I have a modal UserForm that opens when an Excel workbook is opened. When the UserForm is closed, the Excel workbook is saved and closed. I need to be able to view my code, but I can't seem to figure out how to do that because if I close the modal dialog box, the workbook closes. Does anyone know how I can view my code? I really apologize if this is a stupid question, but I can't seem to figure it out.
Thanks for you time and effort.
Without restarting the workbook i.e when the userform is shown in modal, you can use CTRL + Shift + Pause/Break to get into the VBE
Depending on laptops the key combination might change. Here is another which you can try.
Fn + Pause/Break
Hold the shift key when opening the workbook. This allows you to open office applications with macros not running and can be useful in situations like this.
Then view the macros (hit Alt+F11 to open it this editor).
The two other suggestions are good. For easiest debugging, I'd put the code that opens the userform in a separate routine and then call that routine from Workbook_Open. That way you can run and debug your code without having to re-open the workbook.
Then your ThisWorkbook module might look something like this:
Private Sub Workbook_Open()
MyUserformProcedure
End Sub
Sub MyUserformProcedure()
UserForm1.Show
End Sub
You could then comment out the line in Workbook_Open and call MyUserformProcedure, and uncomment the line when you're finished debugging.

Excel won't show the workbooks worksheets

I have an Excel Workbook containing three worksheets. However all sheets seem to be hidden dispite that their visibility is set to xlSheetVisible (Found by looking at the worksheet properties in the VBA editor).
This is what I have tried so far to solve the problem.
Searched Google for help, but all similar problems have been solved by changing the Visibility from xlSheetHidden to xlSheetVisible. But in my case that setting is already set to xlVisible.
By using VBA I have tried to activate a sheet without any result.
By reading this you might have guessed that I am able to see and access the worksheets from the VBA editor.
Despite that looking at the normal Excel userinterface, all buttons are disabled and clicking at the office/file button in the topleft corner doesn't allow me to save the workbook. However if I make any changes to the VBA itself and tries to close the workbook then Excel asks whether or not I would like to save the workbook.
Everything you describe leads me to believe you're hiding the workbook window, not the worksheets. When a workbook window is hidden, all the sheets become hidden and much of the functionality from the toolbar greys out.
In the Visual Basic Editor, you'd also be able to see all of the worksheets and their visibility would be xlVisible, yet they cannot be seen on the screen. This is because they ARE visible, but the window which displays them is not.
Please try clicking the View tab in the toolbar, and then under the Window pane, click Unhide.
If this doesn't work, then try toggling visibility of the workbook.
It sounds like this may really be your problem...
http://vbadud.blogspot.co.uk/2010/08/hide-sheet-tabs-using-vba-hide-excel.html

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))