Results 1 to 18 of 18

Using UserName in Select Case

Threaded View

jomili Using UserName in Select Case 05-21-2010, 04:11 PM
davegugg Re: Using UserName in Select... 05-21-2010, 04:43 PM
snb Re: Using UserName in Select... 05-21-2010, 05:33 PM
jomili Re: Using UserName in Select... 05-24-2010, 08:31 AM
jomili Re: Using UserName in Select... 05-24-2010, 10:59 AM
Kyle123 Re: Using UserName in Select... 05-25-2010, 08:33 AM
jomili Re: Using UserName in Select... 05-25-2010, 08:37 AM
Kyle123 Re: Using UserName in Select... 05-25-2010, 08:44 AM
jomili Re: Using UserName in Select... 05-25-2010, 09:27 AM
  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,065

    Using UserName in Select Case

    I have a macro, code below, which fires when the workbook is opened. It checks to see if the username is written in column A of Sheet2; if it is, it writes the date beside it. If it isn't, it writes the username in the next open cell in column A, puts the date beside it, saves itself, then displays a timed messag of my choosing.

    Right now I can put the UserName (StrUser) in my message, but I want to personalize it more by putting the actual name (User) in the message, and I'm trying it with a Select Case routine, but it's not working. I always plugs in "I don't know who you are", though I've verified my StrUser name is correct. I'd appreciate it if anyone can point out my problem in the code below. BTW, the "Sheet1.Select" statements are because I want my users to only be looking at sheet1.

    Thanks.


    Option Explicit
    Private Sub Workbook_Open()
    
        Dim strUser As String, lrow As Long
        strUser = Environ("username")
        Dim cell As Range
        Dim User As String
        
    
    Application.ScreenUpdating = False
    Sheet1.Select
        
    ' check to see if the file was opened in readonly mode, if so exit sub
        If Me.ReadOnly = True Then Exit Sub
            
    ' can write and save changes - not read only
    With Sheets("Sheet2")
            ' can write and save changes - not read only
            For Each cell In .UsedRange
                If cell.Value = strUser Then
                    cell.Offset(0, 1).Value = Date
                    Exit Sub ' username is present
                End If
            Next cell
        
           With .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
                .Value = strUser
                .Offset(0, 1).Value = Date
            End With
      
           Select Case Cells(Rows.Count, 1).End(xlUp).Text
    
              Case "LUPOREJ"
                
                 User = "John"
    
              'Case "IDUNNO"
    
                  'User = "Somebody else"
            
              Case Else
    
                  User = "I don't know who you are."
    
        End Select
        End With
        Me.Save 'save now to capture username in log
           Sheet1.Select
            CreateObject("WScript.Shell").Popup "Hello" & User & " This is a first attempt at a messaging system within Excel for specific worksheets." & vbCrLf & "This workbook will close itself after 7 seconds, which should be enough time to read this message." & vbCrLf & "If I've done it right you should not see this msgbox again.  Thanks for trying it.", 7, "This Msgbox will close itself."
            'Run "Msgbox_Test()"
                
               
               
       Application.ScreenUpdating = True
       
    
    End Sub
    Last edited by jomili; 05-25-2010 at 09:28 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1