• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Prevent users to add worksheets

Ihave this code that works fine
Code:
Option Explicit
Private Sub Workbook_NewSheet(ByVal Sh As Object)
   
  With Application
  .ScreenUpdating = False
  .DisplayAlerts = False
   
   
  ActiveSheet.Delete
   
  MsgBox "Je kan geen blad toevoegen!", 16
   
   
  .DisplayAlerts = True
  .ScreenUpdating = True
  End With
   
End Sub
But i would like to change it , when i get the message box and if i am an administrator i can fill in a pasword and add a sheet , but not the nomal users
Any help welcome
 
Like below?
Code:
Option Explicit
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim vbMsg As VbMsgBoxResult
Dim strPassword As String
With Application
    .ScreenUpdating = False
    .DisplayAlerts = False
 
    vbMsg = MsgBox("You need administrator password to add new sheet!" & vbCrLf & "Do you have admin password?", vbYesNo)
    If vbMsg = vbYes Then
        strPassword = Application.InputBox("Provide Admin Password", "Password")
        If strPassword <> "abcd" Then
            MsgBox "Wrong Password. Sheet will be deleted!", vbExclamation
            ActiveSheet.Delete
            MsgBox "Je kan geen blad toevoegen!", 16
        End If
    Else
        ActiveSheet.Delete
        MsgBox "Je kan geen blad toevoegen!", 16
    End If
   
    .DisplayAlerts = True
    .ScreenUpdating = True
End With
 
End Sub
 
Back
Top