Results 1 to 11 of 11

Thread: show ms box if the xls file is opened...

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    show ms box if the xls file is opened...

    i have a .xls file into a dir server, with all free permission on this dir, inested the tipical ms message "file is alreday opend from..." when a user open a xls file if other user have opened the same, is possible:

    to show a mshbox:

    Attention this file is in use from & "name of user have opoened the file for first" click on msg box close the .xls file...

    i use this function to know wich user have opened the .xls file:

    Sub USER_NAME()
    Dim wshNet
    ThisWorkbook.Activate
    Sheets("RATE").Select
    Set wshNet = CreateObject("WScript.Network")
    wshGetUserName = wshNet.UserName
    Set wshNet = Nothing
    Range("A1") = ""
    Range("A1") = UCase(wshGetUserName)
    End Sub

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: show ms box if the xls file is opened...

    I don't think you want to close a file that someone has been working on. It would cause them to lose their work!

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: show ms box if the xls file is opened...

    I think luca90 just want to show the msgbox, the same way that Excel does,
    and if the file is opened by another user then show the msgbox with the name of that user and close. He don't want to close the file opened by the other user, he wants to close the file in the local machine, finally it would be closing the Excel App I think.

    Excel also gives the posibility of opening a new copy of the workbook.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    Re: show ms box if the xls file is opened...

    Quote Originally Posted by jcis
    I think luca90 just want to show the msgbox, the same way that Excel does,
    and if the file is opened by another user then show the msgbox with the name of that user and close. He don't want to close the file opened by the other user, he wants to close the file in the local machine, finally it would be closing the Excel App I think.

    Excel also gives the posibility of opening a new copy of the workbook.
    Yes.... perfect!
    how to do this?

  5. #5
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: show ms box if the xls file is opened...

    Not much in the forums about this, the closer I could get with some searches:

    Look here post #3, by Robdog:
    Another thread

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: show ms box if the xls file is opened...

    Maybe you could use GetUserName API and comapare with the names you already have, if there is an user using the Workbook, and his Username is diferent than the active username you could show that username in the Msgbox as you want, and close the workbook.

    GetUserName Example, Im not sure if this is in the same format that the usernames you already have..

    VB Code:
    1. Option Explicit
    2. Private Declare Function GetUserName Lib "advapi32.dll" _
    3. Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    4.  
    5. Private Function GetActiveUserName() as String
    6. Dim UserName As String, nSize As Long
    7.  
    8.     Call GetUserName(vbNullString, nSize)
    9.     UserName = Space(nSize)
    10.     Call GetUserName(UserName, nSize)
    11.     GetActiveUserName = UserName
    12.  
    13. End Function
    Last edited by jcis; Nov 25th, 2005 at 08:10 AM.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    Re: show ms box if the xls file is opened...

    Quote Originally Posted by jcis
    Maybe you could use GetUserName API and comapare with the names you already have, if there is an user using the Workbook, and his Username is diferent than the active username you could show that username in the Msgbox as you want, and close the workbook.

    GetUserName Example, Im not sure if this is in the same format that the usernames you already have..

    VB Code:
    1. Option Explicit
    2. Private Declare Function GetUserName Lib "advapi32.dll" _
    3. Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    4.  
    5. Private Function GetActiveUserName() as String
    6. Dim UserName As String, nSize As Long
    7.  
    8.     Call GetUserName(vbNullString, nSize)
    9.     UserName = Space(nSize)
    10.     Call GetUserName(UserName, nSize)
    11.     GetActiveUserName = UserName
    12.  
    13. End Function
    not for me...;-(
    Example please, tks.

  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: show ms box if the xls file is opened...

    what? GetUserName doesn't work?

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,941

    Re: show ms box if the xls file is opened...

    Quote Originally Posted by jcis
    what? GetUserName doesn't work?
    ...no work fine
    But not have a knoldedgmet to make the vba code:-(

  10. #10
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: show ms box if the xls file is opened...

    I really don't know much about VBA. Maybe someone who knows, see this post now. By the way, there is a VBA forum too.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: show ms box if the xls file is opened...

    I dont quite get the problem as Excel displays a dialog prompt if you attempt to open a file that is already opened by another user. It gives you the Notify or Open as Read-Only options. It also identifies the user that has it opened first (exclusively).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width