+ Reply to Thread
Results 1 to 13 of 13

automatically check who's logged in with VBA?

  1. #1
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    automatically check who's logged in with VBA?

    Hi Folks,

    Short summary of my problem: Is there a way to have a macro check who is logged in on a computer and store that information?

    Explanation why I need this:

    For our main customer, we send invoices once a month and currently, we use a macro which copies the relevant information to a new spreadsheet, sorts it by department (because each department has to pay it's own bills...what a surprise) and automatically saves that spreadsheet as mm-yyyy.xlsx (e.g. 09-2015.xlsx).
    However, our secretary then still has to copy the data per department to a Word file, which she then sends to our financial dept., who turn it into an official invoice. Since we usually have quite a large number of invoices per month, making the Word files can sometimes take half a day or more and that's a bit of a waste of time.

    We now, finally, have 'permission' from our financial dept. to send pdf's instead of Word files and of course, making a pdf from Excel can easily be incorporated in the macro.
    But here comes the problem: We work with a very strict quality control system and need some way to verify who did what. I was first thinking about making some kind of popup window in the macro in which the person running the macro needs to fill in his/her initials before the macro continues. And to have the macro include those initials in the name of the excelsheet when it's saved.

    But as our QA manager pointed out: I can just as easily fill in somebody else's initials. Of course, we expect people not to do that, but the board of accreditation will probably see that differently (they usually do).

    So what we were thinking now is to have the macro check who is logged in on the computer on which the macro is run and include those data in the spreadsheet, either in a set place on one of the sheets or, preferably, in the file-name.
    And of course, we know that it is still possible to run the macro on a computer on which somebody else is logged in but hey....we can't cover everything.

    Hope you can help me.

    Cheers,
    Thirsa

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: automatically check who's logged in with VBA?

    This function:
    Please Login or Register  to view this content.
    Will return the windows logon of the person who is running the macro (well logged into windows at the time anyway)

  3. #3
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: automatically check who's logged in with VBA?

    Cool, I'll see if I can incorporate this into my macro.
    Thanks for the quick reply!
    Thirsa

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: automatically check who's logged in with VBA?

    Hi,

    There's a VBA environment system variable which you could use.

    Please Login or Register  to view this content.
    This takes the name that was recorded when any particular Excel licence was installed. The name is held in the Excel Options General parameter.

    Edit:

    Note. This is subtly different to Kyle's Environ("UserName").
    Last edited by Richard Buttrey; 09-21-2015 at 04:34 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: automatically check who's logged in with VBA?

    And less reliable. Is there a reason for using it Richard? I tend to avoid it

  6. #6
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: automatically check who's logged in with VBA?

    Hi Richard,

    I don't know if your solution will work for us, since as far as I know, when software is installed, the name of the hospital we are part of is recorded instead of individual usernames. But I'm not completely certain of this. I'll simply try both options and see which works best.

    Cheers,
    Thirsa

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: automatically check who's logged in with VBA?

    Obviously you can only use whatever is recorded. It would seem a shame not to use the Excel personal UserName variable when installing Excel since that is presumably what it's designed for.

  8. #8
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: automatically check who's logged in with VBA?

    Quote Originally Posted by Richard Buttrey View Post
    It would seem a shame not to use the Excel personal UserName variable when installing Excel since that is presumably what it's designed for.
    I coudn't agree more, but unfortunatly the folks in our ICT dept. and I don't always see eye to eye.
    But like I said, I'm not completely certain about what name is recorde when software is installed, so I'll simply try which solution works best.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: automatically check who's logged in with VBA?

    @Richard, not quite. Where you have multiple users on one machine, you can only insert one username for office.

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: automatically check who's logged in with VBA?

    Quote Originally Posted by Kyle123 View Post
    @Richard, not quite. Where you have multiple users on one machine, you can only insert one username for office.
    Indeed so.
    The OP was not explicit on this point but the last comment seemed to suggest that for most cases that the logged on computer was person specific, or at least that's the way I interpreted it.

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: automatically check who's logged in with VBA?

    That's why I asked what the reason for is in using it. I don't understand why it's so widely adopted when it's so frequently incorrect - I'd always go for Environ

  12. #12
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: automatically check who's logged in with VBA?

    @Richard: Your interpretation is correct. It is indeed so that most computers here are used by only one person and I expect the invoice macro to be run only from such computers (usually the secretary's computer and if she's not in either mine or the computer of the head of our dept.).

  13. #13
    Registered User
    Join Date
    09-13-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: automatically check who's logged in with VBA?

    I've decided to go with for Environ, just to be certain (no offence Richard) and my spreadsheet is now saved as mm-yyyy_username.xmlx.
    Thanks again guys!

    Thirsa

+ 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. Check Box Automatically in every row.
    By eb1102 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-22-2015, 04:57 PM
  2. [SOLVED] In VBA, how do you program a check box to automatically check the box?
    By redsab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2013, 06:19 AM
  3. Automatically check one or more check boxes when a parent check box is manually checked
    By Steverizer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-28-2013, 01:56 PM
  4. User name - currently logged on.
    By Caula in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2012, 11:14 AM
  5. Tick Check Box Automatically
    By fialko in forum Excel General
    Replies: 0
    Last Post: 07-08-2011, 02:04 PM
  6. User that is logged in
    By Gunilla in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-05-2010, 01:14 PM
  7. Logged in User
    By mikesjd110 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-13-2009, 08:26 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