+ Reply to Thread
Results 1 to 6 of 6

Macro for Login attendance

  1. #1
    Forum Contributor
    Join Date
    09-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    239

    Macro for Login attendance

    Private Sub Workbook_Open()
    Dim myEMPID As String
    Dim logWB As Workbook
    Dim logWS As Worksheet
    Dim logNextRow As Long
    '
    'this must hold the full path and filename to the workbook you will
    'record the employee ID and login time into
    Const LogWorkbookPath = "D:\Users\Username\LogBook.xlsx"
    'this must provide the name of the sheet in LogBook.xlsx to
    'put the employee ID into
    Const logSheetName = "User Log"
    'this must be the column to put the employee ID into
    Const logEmpIDColumn = "A"
    'this must provide the column to put the logIN time into
    Const logInTimeColumn = "B"

    'force the user to provide an input before continuing
    Do While myEMPID = ""
    myEMPID = InputBox("Enter your Employee ID to Log In", "Log In", "")
    Loop
    'prepare to open the log workbook
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    'open the log workbook
    Workbooks.Open LogWorkbookPath
    Set logWB = ActiveWorkbook
    Set logWS = logWB.Worksheets(logSheetName)
    logNextRow = logWS.Range(logEmpIDColumn & Rows.Count).End(xlUp).Row + 1
    logWS.Range(logEmpIDColumn & logNextRow) = myEMPID ' enter EMPID
    logWS.Range(logInTimeColumn & logNextRow) = Now() ' enter login date/time
    logWB.Close True ' close and save changes
    Set logWS = Nothing
    Set logWB = Nothing
    End Sub

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim myEMPID As String
    Dim logWB As Workbook
    Dim logWS As Worksheet
    Dim logLastRow As Long
    '
    'this must hold the full path and filename to the workbook you will
    'record the employee ID and logout time into
    Const LogWorkbookPath = "D:\Users\Username\LogBook.xlsx"
    'this must provide the name of the sheet in LogBook.xlsx to
    'put the employee ID into
    Const logSheetName = "User Log"
    'this must be the column to put the employee ID into
    Const logEmpIDColumn = "A"
    'this must provide the column to put the logOUT time into
    Const logOutTimeColumn = "C"
    '
    'loop until the user provdes an input
    Do While myEMPID = ""
    myEMPID = InputBox("Enter your Employee ID to Log Out", "Log Out", "")
    Loop
    'prepare to open the log workbook
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    'open the log workbook
    Workbooks.Open LogWorkbookPath
    Set logWB = ActiveWorkbook
    Set logWS = logWB.Worksheets(logSheetName)
    'we are assuming that the last entry on the sheet was
    'made by YOU logging in earlier, not someone else.
    logLastRow = logWS.Range(logEmpIDColumn & Rows.Count).End(xlUp).Row
    logWS.Range(logEmpIDColumn & logLastRow) = myEMPID ' enter EMPID
    logWS.Range(logOutTimeColumn & logLastRow) = Now() ' enter login date/time
    logWB.Close True ' close and save changes
    Set logWS = Nothing
    Set logWB = Nothing
    End Sub
    Last edited by srinivasan1965; 09-23-2015 at 04:10 AM.

  2. #2
    Forum Contributor
    Join Date
    09-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    239

    Re: Macro for Login attendance

    Hi
    I am able to use this file
    I am unable to use cancel button
    Can anybody suggest on this
    I am attaching the files

    Thanks & Regards
    Attached Files Attached Files

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Macro for Login attendance

    You have 60 posts, you need to be using code tags.

    Please go back to your first post, click edit, highlight all your code then click the # on the tool bar and choose save changes.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  4. #4
    Forum Contributor
    Join Date
    09-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    239

    Re: Macro for Login attendance

    Hi
    Done
    is it possible to modify the code while entering id it displays date and time also on the screen
    Thanks

  5. #5
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Macro for Login attendance

    Quote Originally Posted by srinivasan1965 View Post
    Hi
    Done
    is it possible to modify the code while entering id it displays date and time also on the screen
    Thanks
    It doesn't look like it worked.

    After putting code tags around the code and saving the changes you should see your code go from looking like this.

    Sub Test()

    End Sub

    To this:
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    09-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    239

    Re: Macro for Login attendance

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 10
    Last Post: 03-17-2016, 05:34 AM
  2. Macro required for Attendance tracker - Login and Logout
    By nirmalreigns in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2015, 03:19 PM
  3. Need Help - AutoCalculate Attendance Points for employee attendance records
    By switzd0d in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-17-2015, 03:00 PM
  4. Replies: 9
    Last Post: 10-11-2014, 12:29 PM
  5. Create automated attendance with login Name?
    By marc5354 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-15-2014, 06:46 AM
  6. login attendance macro
    By ringgo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-06-2013, 12:06 PM
  7. Excel Macro for creating Attendance rerort when executive login in the system
    By medhekaraniruddha in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-14-2012, 08:39 AM

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