I have excel vba. As soon as I open excel file, the UserForm also opens without opening WorkBook. I can open Workbook with a button click but I want it to be read-only and not editable.
Now I have activated write protection under File -> Info -> write protection. Now when I open the excel file the message appears:
"The author would prefer you to open 'file.xlsm' read-only - unless you need to make changes. Open read-only?"
That's not what I want. Is there a way to ignore the message or to automatically confirm with "yes" so that when someone opens the excel file, the message does not appear?
Note: I dont want to use the code
Set wb = Workbooks.Open(Filename:=MyFile, ReadOnly:=True)
because i directly open UserForm when i open excel and workbook is not displayed, so i can't use this code. if you want to know how I open a file, here is also my code on how to open UserForm without opening workbook. Code in my ThisWorkBook:
Private Sub Workbook_Open()
showLoginForm
End Sub
Code for showLoginForm:
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
ThisWorkbook.Windows(1).Visible = False
End If
UserForm5.show vbModeless
End Sub