Not an answer, but I can't post this as a comment. I think the userform1.show needs to be called after the execution of if statement.
Solution without infinite loop - schedule hiding of Excel:Īpplication.OnTime Now + TimeValue("00:00:01"), "HideExcel" Then just to make sure that Excel is closed once that modeless UserForm is closed I've added this: Only solution I've found thus far is this one - basically you suspend the execution by adding an infinite loop so Excel only gets to end of this event once you get rid of (Unload/Hide) the form that was shown previously. If we change ShowModal to False (or call UserForm.Show vbModeless) then the execution is never suspended and once we reach End Sub of our Workbook_Open(), Excel appears to set Application.Visible = True on its own. The reason why it's working with UserForm property ShowModal set to True is because: the execution is suspended - it's waiting for user to interact with the UserForm that was shown. I found myself having the exact same problem - modeless form opened with Workbook_Open() event that's also supposed to hide excel app (working on Excel 2016, 32bit). So it might have something to do with the way newer Office Apps handle stuff.
Excel vba on errorvbmodaless is blank code#
Might have to start it twice, because when the macros are blocked at startup and only activated after excel has completely loaded, the code works as intended.Įdit: I was able to test this on an excel 2010 pc and there the problem doesn't exist. Instead of the "if"-clause, Excel still stays visible and of course so does the active window.Įdit: Link to my test file: Test File on my Dropbox Anyway, it doesn't work anymore as intended, no matter the modal setting now. I suspect changing the ShowModal setting in the editor screwed it up somehow, but that's just me guessing. The first time I ran this, it worked fine. Also, Excel, not the userform, has focus after loading everything.
However, if I click the button on the worksheet, Excel, or the window, are hidden as they should. When I open the workbook, the userform shows up, but excel and the active window stay visible as well. The last thing is a button on the first worksheet, to start the same process as when the workbook is opened. The only code for this userform is:Īpplication.Windows("test.xlsm").Visible = True I have an empty userform with one single button. It's the only code for the workbook.Īpplication.Windows("test.xlsm").Visible = False Excel VBA application.visible immediately set back to True - excel I have set up a new, empty, modeless userform, to fix my problem with the least amount of code involved.įor when the workbook is opened, the following code is executed to hide Excel and show the userform.