+ Reply to Thread
Results 1 to 5 of 5

Display username in message box that has a file open

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Display username in message box that has a file open

    I have bit of code that:
    (1) opens another spreadsheet
    (2) updates that spreadsheet
    (3) saves that spreadsheet
    (4) closes that spreadsheet

    If the spreadsheet that requires updating is open by another user, I display a message indicating the file is open and no updates occured. There are about 20 persons within the organization that may have this file open? Is there away to display the username of the person who has the file open? Thanks in advance for any comments.
    Last edited by maacmaac; 02-03-2010 at 10:54 AM.

  2. #2
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Display username in message box that has a file open

    Do you mean something like this?

    Please Login or Register  to view this content.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Display username in message box that has a file open

    Hi Maacmaac,

    According to this site: http://excel.tips.net/Pages/T002492_...File_Open.html

    It's not possible to get this directly through VBA, but the article does offer an alternative. In the workbook create an AutoOpen macro (or Workbook Open event) so that the current user's info is stored in a hidden sheet.

    If you go that route, don't use 'Application.Username' as that can contain anything from blank to an old user name. Use Environ("username") to get the username that is currently logged into Windows. Also, Environ("computername") will give you the PC name it is open on.

    Hope that helps!

  4. #4
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: Display username in message box that has a file open

    Ended up adding code to check name of user that has spreadsheet open.
    Please Login or Register  to view this content.
    Thanks for comments.

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Display username in message box that has a file open

    Glad you have it sorted out. If your users log into Windows via a domain or even group, I'd still recommend you go with
    Please Login or Register  to view this content.
    vs.
    Please Login or Register  to view this content.
    Application.Username simply pulls the value from: Office Button -> Excel Options -> Popular -> User Name. You could put Scooby Doo in there, or leave it blank, and that's what will be returned. By using Environ("username") you get the name of the user that is currently logged into the PC (windows/domain).

+ Reply to Thread

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