• 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.

User Name match the criteria then Exit

Abhijeet

Active Member
Hi
I want to user name case match then End Sub please tell me how to do this
Code:
Private Sub Workbook_Open()
'the name of the current user
Dim UserName As String
'on opening, find out who this is (and convert to lower case)
UserName = LCase(Environ("UserName"))
'if this is one of two specified Wise Owls ...
Select Case UserName
Case "geena.davis", "susan.sarandon"
'display a greeting and change default cell colour
MsgBox "Hello, Thelma/Louise"
Styles("Normal").Interior.Color = RGB(240, 255, 255)
Case Else
'otherwise, just continue
End Select
End Sub
 
@Abhijeet
Didn't I give you the code to do almost the same thing? Both in thread and in private conversation.

Just remove the portion where I disabled all macro in the code. But if it's going to be applied to the same code you had before, you need to replicate the code in more than one location (since you have multiple Worksheet/Workbook events firing codes).
 
Hi Chihiro

I know u gave me this code but how to use Select case method i want to know about this
Code:
Private Sub Workbook_Open()
    'Force the current selection to be selected, triggering the appropriate
    'state of the cut, copy & paste commands
    Application.EnableEvents = True

Dim uName As String
Dim uList As Range

uName = Environ("UserName")

With Sheets("Sheet2").Range("lstUser")
    Set uList = .Find(What:=uName, _
                      LookIn:=xlValues, _
                      LookAt:=xlWhole, _
                      SearchOrder:=xlByRows, _
                      SearchDirection:=xlNext, _
                      MatchCase:=False)
        If Not uList Is Nothing Then
            Application.EnableEvents = False
            'Selection.Select
        Else
            Selection.Select
            Exit Sub
        End If
End With
   
End Sub
 
Like Marc stated, just add Exit Sub in the code.
Code:
Private Sub Workbook_Open()
'the name of the current user
Dim UserName As String
'on opening, find out who this is (and convert to lower case)
UserName = LCase(Environ("UserName"))
'if this is one of two specified Wise Owls ...
Select Case UserName
Case "geena.davis", "susan.sarandon"
'display a greeting and Exit Sub
MsgBox "Hellow " & UserName & " exiting out of sub routine"
Exit Sub
Case Else
'otherwise, just continue
End Select
End Sub
 
I use in this macro but not work can u pls tell me what is wrong
 

Attachments

  • Mr Excel Code Copy Paste disable test.xlsm
    483.8 KB · Views: 1
If it's variant of what I helped you with. Then as I said in post #6. You either have to add same check on each event that fires Macro. Or you can just use Application.EnableEvents = False like I showed you in IF statement (just tuck it after MsgBox).

Remember to turn it to "True" before you close the workbook.
 
Back
Top