Daugaard92
New Member
- Joined
- Nov 20, 2020
- Messages
- 17
- Office Version
- 2016
- Platform
- Windows
Hello.
So I've sheet, which I'd like to lock and "hide" from others on our shared network.
My preliminary solution to this is using codes that autorun, when the worksheets opens/closes:
Sub Auto_Open()
Dim MyInput As String
MyInput = InputBox("Indtast venligst koden til arket. Kontakt evt. Mathias Laursen.", "Indtast Kode.", "INDTAST KODE HER")
If MyInput = "PASSWORD" Then
ActiveWorkbook.Unprotect "PASSWORD"
Range("A1").Value = "Ulåst"
Sheets("Målstyring").Visible = True
Sheets("Mål").Visible = True
Sheets("Mål").Select
Sheets("Forside").Visible = False
Else
MsgBox ("Forkert kode. Prøv venligst igen, eller kontakt Mathias Laursen.")
End If
End Sub
When the sheet opens it prompts for the "PASSWORD"-input - and I've a similar code which runs, when the workbook closes. When the worksheet is in its "locked"-state, it prevents the user from viewing and/or accessing the hidden sheets ("Mål") and ("Målstyring") - and instead forcing the user to view the ("Forside")-sheet.
As you can tell, I'm very new to VBA and a flaw of the method above, is obviously that the user can simply see the password to unlock the sheet, by accessing VBA (Though few of my coworkers use it). Still, I'd like to make a better password/lock for the sheet.
Is it therefore possible; In VBA, to make a user-generated password with input, which the user can't see when viewing the code? Alternatively, if anoyone know of a simpler and better method for both locking and hiding a sheet - Please feel free to comment. I hope it makes sense. Cheers.
So I've sheet, which I'd like to lock and "hide" from others on our shared network.
My preliminary solution to this is using codes that autorun, when the worksheets opens/closes:
Sub Auto_Open()
Dim MyInput As String
MyInput = InputBox("Indtast venligst koden til arket. Kontakt evt. Mathias Laursen.", "Indtast Kode.", "INDTAST KODE HER")
If MyInput = "PASSWORD" Then
ActiveWorkbook.Unprotect "PASSWORD"
Range("A1").Value = "Ulåst"
Sheets("Målstyring").Visible = True
Sheets("Mål").Visible = True
Sheets("Mål").Select
Sheets("Forside").Visible = False
Else
MsgBox ("Forkert kode. Prøv venligst igen, eller kontakt Mathias Laursen.")
End If
End Sub
When the sheet opens it prompts for the "PASSWORD"-input - and I've a similar code which runs, when the workbook closes. When the worksheet is in its "locked"-state, it prevents the user from viewing and/or accessing the hidden sheets ("Mål") and ("Målstyring") - and instead forcing the user to view the ("Forside")-sheet.
As you can tell, I'm very new to VBA and a flaw of the method above, is obviously that the user can simply see the password to unlock the sheet, by accessing VBA (Though few of my coworkers use it). Still, I'd like to make a better password/lock for the sheet.
Is it therefore possible; In VBA, to make a user-generated password with input, which the user can't see when viewing the code? Alternatively, if anoyone know of a simpler and better method for both locking and hiding a sheet - Please feel free to comment. I hope it makes sense. Cheers.
Last edited by a moderator: