Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
win api function
Inside of a VBA / excel macro, is there a function I can
call to get the nt login of the current user? Any help much appreciated. Randy |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
win api function
Hi Randy,
Here's a response I posted the other day to m.p.e.misc: You can get the username from one of two places: 1) an environment variable: MsgBox Environ$("Username") 2) the Windows API: Private Declare Function GetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long Public Function gsGetUsername() As String Dim sName As String * 255 Dim nPos As Integer GetUserName sName, 255 nPos = InStr(1, sName, vbNullChar) If nPos Then gsGetUsername = Left$(sName, nPos - 1) End Function MsgBox gsGetUsername I typically use #2, as I feel it is more reliable than #1. In your Workbook_Open routine (double-click ThisWorkbook in the VBE to get to the applicable codepane), you could check to see if a cell has a value - if not, put the username the Private Sub Workbook_Open() If Len(Sheets("Sheet1").Range("A1").Value) = 0 Then Sheets("Sheet1").Range("A1").Value = gsGetUsername End If End Sub -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Randy wrote: Inside of a VBA / excel macro, is there a function I can call to get the nt login of the current user? Any help much appreciated. Randy |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel Data Validation/Lookup function does function correcty | Excel Worksheet Functions | |||
copy of excel file not showing formulal/function in the function b | Excel Discussion (Misc queries) | |||
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) | Excel Worksheet Functions | |||
Emulate Index/Match combo function w/ VBA custom function | Excel Worksheet Functions | |||
User-Defined Function pre-empting Built-in Function? How to undo???? | Excel Programming |