I have an excel file with UserForm1. I have the following codes (see below) as soon as I open the file only UserForm1 is displayed and the file is not. So far everything fits but when I open another excel file, the invisible excel file (where UserForm1 is) becomes visible again. But I want it to remain invisible and only UserForm1 is visible, even if I open and close other excel files.
Code in my module:
Sub showLoginForm() If isSheetVisible Then ' Only Hide this workbook and keep the other workbooks visible ThisWorkbook.Windows(1).Visible = False Else ' There is no other workbook visible, hide Excel Application.Visible = False End If UserForm1.Show vbModeless End Sub Function isSheetVisible() As Boolean ' Checks if any workbook except the current one is visible Dim wb As Workbook For Each wb In Application.Workbooks If Not wb Is ThisWorkbook Then Dim win As Window For Each win In wb.Windows If win.Visible Then isSheetVisible = True Next End If Next End Function Code in my workbook:
Private Sub Workbook_Open() UserForm1_Initialize 'ignore it not relevant for the question showLoginForm End Sub Showing the problem visul (sorry cant get video)
all good sofar now opening another excel file and my text excel will open as well, what i dont want:
I might need a code where when another file is opened after UserForm1 opened, UserForm1 is automatically asked if another file has been opened, if yes then ThisWorkBook.visible = False is used again. If so, how do I write such a code so that it will automatically be execute without doing anything?


when I open another excel fileis it opened by users or VBA code?