Hello:
Please refer to attached file.
I am trying to put the code in the workbook so that the excel file can be open only if the computer name is as assigned.
However, it is malfunctioning although i have correct Computer name (User as below) in the code.
Would appreciate if you can help me with this to solve
1st set of code is in "ThisWorkbook"
Private Sub Workbook_Open()
'Unhide all worksheets
Application.ScreenUpdating = False
Call XQuit
Call ShowAllSheets
Application.ScreenUpdating = True
End Sub
Below code in Module
Sub XQuit()
Dim User As String, passWord As String
User = "NBook;" 'separate with ";"
If CBool(InStr(1, User, Environ("computername") & ";")) Then
MsgBox ("Workbook is enabled")
'workbbok is enabled show its content
Else
MsgBox "You are trying to access restricted panel.", vbCritical, "Access Denied"
passWord = InputBox("Password for Manual Access:", vbCritical, "Automatic Access Denied - Last Chance")
If passWord <> "1111" Then Application.Quit
End If
End Sub
Sub ShowAllSheets()
'Show all worksheets except the macro welcome page
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVisible
Next ws
Worksheets("Macros").Visible = xlSheetVeryHidden
End Sub
Sub HideAllSheets()
'Hide all worksheets except the macro welcome page
Dim ws As Worksheet
Worksheets("Macros").Visible = xlSheetVisible
For Each ws In ThisWorkbook.Worksheets
If Not ws.Name = WelcomePage Then ws.Visible = xlSheetVeryHidden
Next ws
'Worksheets(WelcomePage).Activate
Worksheets("Macros").Activate
End Sub
Let me know if you have any questions.
Thanks.
Riz
Bookmarks