|
-
Nov 25th, 2005, 05:31 AM
#1
Thread Starter
PowerPoster
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
-
Nov 25th, 2005, 05:45 AM
#2
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!
-
Nov 25th, 2005, 06:05 AM
#3
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.
-
Nov 25th, 2005, 06:43 AM
#4
Thread Starter
PowerPoster
Re: show ms box if the xls file is opened...
 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?
-
Nov 25th, 2005, 07:53 AM
#5
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
-
Nov 25th, 2005, 08:07 AM
#6
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:
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Function GetActiveUserName() as String
Dim UserName As String, nSize As Long
Call GetUserName(vbNullString, nSize)
UserName = Space(nSize)
Call GetUserName(UserName, nSize)
GetActiveUserName = UserName
End Function
Last edited by jcis; Nov 25th, 2005 at 08:10 AM.
-
Nov 25th, 2005, 08:36 AM
#7
Thread Starter
PowerPoster
Re: show ms box if the xls file is opened...
 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:
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Function GetActiveUserName() as String
Dim UserName As String, nSize As Long
Call GetUserName(vbNullString, nSize)
UserName = Space(nSize)
Call GetUserName(UserName, nSize)
GetActiveUserName = UserName
End Function
not for me...;-(
Example please, tks.
-
Nov 25th, 2005, 08:38 AM
#8
Re: show ms box if the xls file is opened...
what? GetUserName doesn't work?
-
Nov 25th, 2005, 08:47 AM
#9
Thread Starter
PowerPoster
Re: show ms box if the xls file is opened...
 Originally Posted by jcis
what? GetUserName doesn't work?
...no work fine
But not have a knoldedgmet to make the vba code:-(
-
Nov 25th, 2005, 10:24 PM
#10
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.
-
Nov 25th, 2005, 10:47 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|