Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I am writing code to open another Excel file. If the file is in use by another user, I would like to use an API function to return the network username of the person who has the file open. Any suggestions? Thanks in advance Paul Martin Melbourne, Australia |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You should be able to get away without APIs.
Open the workbook Read only, then check the WriteReservedBy property of the workbook. With ActiveWorkbook If .WriteReserved = True Then MsgBox "Opened by " & .WriteReservedBy End If End With -- HTH RP (remove nothere from the email address if mailing direct) "Paul Martin" wrote in message ups.com... Hi I am writing code to open another Excel file. If the file is in use by another user, I would like to use an API function to return the network username of the person who has the file open. Any suggestions? Thanks in advance Paul Martin Melbourne, Australia |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Bob
Thanks for the reply. Firstly, WriteReserved returns False, and secondly, WriteReservedBy returns the Excel username. The problem with the latter is that this does not identify the actual username. I would like to get the network username, hence the need for an API. I've found an API from the newsgroups that returns the network name: Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, nSize As Long) As Long I can use this to get my username, but I want to get the username of the user who has the file open that I am attempting to open through code. Regards Paul |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Bob Phillips" wrote in message
You should be able to get away without APIs. Open the workbook Read only, then check the WriteReservedBy property of the workbook. With ActiveWorkbook If .WriteReserved = True Then MsgBox "Opened by " & .WriteReservedBy End If End With I could be wrong, but doesn't that just give you the name that the machine that has opened the file has entered in excel - tools - options? It *should* be correct, but isn't definitively the user who is logged in. Of course, you could also argue that someone could log in under a different network username anyway! An example of the Win32 API is as follows (I think I got this from this newsgroup, but as is often the case, I didn't record the original source, so apologies to the OP of this function and thanks too!): +-+-++-+-++-+-++-+-++-+-++-+-+- Private Declare Function GetNetworkUserName Lib "advapi32.dll" Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ ByRef nSize As Long) As Long 'Get the user's login ID Function NetworkUserName() As String 'A buffer that the API function fills with the login name Dim sBuffer As String * 255 'Variable to hold the length of the buffer Dim lStringLength As Long 'Initialize to the length of the string buffer lStringLength = Len(sBuffer) 'Call the API function, which fills the buffer 'and updates lStringLength with the length of the login ID, 'including a terminating null - vbNullChar - character GetNetworkUserName sBuffer, lStringLength If lStringLength 0 Then 'Return the login id, stripping off the final vbNullChar NetworkUserName = Left$(sBuffer, lStringLength - 1) End If End Function +-+-++-+-++-+-++-+-++-+-++-+-+- HTH, Alan. -- The views expressed are my own, and not those of my employer or anyone else associated with me. My current valid email address is: This is valid as is. It is not munged, or altered at all. It will be valid for AT LEAST one month from the date of this post. If you are trying to contact me after that time, it MAY still be valid, but may also have been deactivated due to spam. If so, and you want to contact me by email, try searching for a more recent post by me to find my current email address. The following is a (probably!) totally unique and meaningless string of characters that you can use to find posts by me in a search engine: ewygchvboocno43vb674b6nq46tvb |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Alan
That function will return MY network login. I want the network username of the person who has a file open that I am programatically opening. Paul |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm not sure if it's possible, but you may want to try posting the same question
in one of the VB newsgroups. Well, if no one gives an acceptable answer here. Paul Martin wrote: Alan That function will return MY network login. I want the network username of the person who has a file open that I am programatically opening. Paul -- Dave Peterson |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It is possible using either NetFileGetInfo or NetFileEnum APIs (I'm not
sure which), but I haven't been able to find a suitable wrapper to utilise them. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2007 - Open a file with more than one person | Excel Discussion (Misc queries) | |||
Unable to save file to Windows 98 network folder | Excel Discussion (Misc queries) | |||
Looking for network-username with Excel macro | Excel Programming | |||
Finding the Username of a user who has a shared Network file open. | Excel Programming | |||
Network detects if Windows Username is online | Excel Programming |