Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Using the Windows API to extract the Windows User Name

Hi,

I found this information on another website: (I am trying
to use the Windows API to extract the login information of
the user who has a workbook open for editing.

Just a thought: if this is your workbook (or at least you
have control over it)and you want to know who is opening
it, you could write code in the Workbook_Open event which
captures the user's userID, name, etc (using Windows APIs)
and persist these values somewhere visible to you. An
extension to this idea is to get the workbook to regularly
poll (using the OnTime method) a database, text file on
the network, etc where you can set a value to tell the
workbook to close, effectively throwing out the current
user so that you can open the workbook.

--

"PS" wrote in message
...
Hello,

In a Network Computer, an Excel file is opened by

someone (eg. PS)

When I open the Excel file, this message dialog is

prompted

aaa.xls is locked for editing by 'PS'

Open ..... ...... ....... ..... ..... ...... ...... in

use.

My Question is "Is there any way to extract 'PS' ?"
Maybe API ?

Thanks in advance.


This is my question. How do I use the Windows API to
extract the Windows login information (username) to use in
the Workbook_Open event of who has the Excel workbook open
for editing.

Any help would be greatly appreciated

Thanks,

Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Using the Windows API to extract the Windows User Name

Cut and paste this code into a module. The function returns the User name of
the person logged into the computer.

Option Explicit


'-----------------------------------------------------------------------------------------------------
' This module only provides the username
'================================================= ================================================== ==


Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long


Public Function ReturnNTUserName() As String

' Returns the NT Domain User Name

Dim rString As String * 255, sLen As Long, tString As String
Dim NWUserName As String

tString = ""

On Error Resume Next
sLen = GetUserName(rString, 255)
sLen = InStr(1, rString, Chr(0))
If sLen 0 Then
tString = Left(rString, sLen - 1)
Else
tString = rString
End If
On Error GoTo 0

NWUserName = Left(Right(tString, Len(tString) - 1), Len(tString) - 2)
ReturnNTUserName = UCase(Left(tString, 1)) + NWUserName +
Right(UCase(tString), 1)

End Function




"Mike" wrote:

Hi,

I found this information on another website: (I am trying
to use the Windows API to extract the login information of
the user who has a workbook open for editing.

Just a thought: if this is your workbook (or at least you
have control over it)and you want to know who is opening
it, you could write code in the Workbook_Open event which
captures the user's userID, name, etc (using Windows APIs)
and persist these values somewhere visible to you. An
extension to this idea is to get the workbook to regularly
poll (using the OnTime method) a database, text file on
the network, etc where you can set a value to tell the
workbook to close, effectively throwing out the current
user so that you can open the workbook.

--

"PS" wrote in message
...
Hello,

In a Network Computer, an Excel file is opened by

someone (eg. PS)

When I open the Excel file, this message dialog is

prompted

aaa.xls is locked for editing by 'PS'

Open ..... ...... ....... ..... ..... ...... ...... in

use.

My Question is "Is there any way to extract 'PS' ?"
Maybe API ?

Thanks in advance.


This is my question. How do I use the Windows API to
extract the Windows login information (username) to use in
the Workbook_Open event of who has the Excel workbook open
for editing.

Any help would be greatly appreciated

Thanks,

Mike

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
i want all windows in one excel frame (windows in taskbar) Subramanya Excel Discussion (Misc queries) 1 December 18th 09 03:14 PM
cannot open exel from windows xp in windows vista and visa versa lildiana New Users to Excel 4 February 25th 09 07:26 PM
can windows vista edit shared document from windows xp sasa Excel Worksheet Functions 1 January 9th 08 06:44 PM
Page breaks are different in Windows 2000 and Windows XP Bill Allen Excel Discussion (Misc queries) 1 November 23rd 05 04:42 PM
Use Windows Script to run Windows Explorer Search? Ian Elliott[_3_] Excel Programming 0 January 12th 04 05:03 PM


All times are GMT +1. The time now is 10:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"