Views

Histats

Vitrine

VBA - Retornando nome de usuário logado na máquina.

Cole o código abaixo em um novo módulo e faça referência a atcNames: ? "User: " & atCNames(1) & "- " & Trim(atCNames(2)), Now() Private Declare Function api_GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function api_GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Public Function atCNames(UOrC As Integer) As String ' Author: Date: Contact: ' André Bernardes 06/06/2009 07:23 bernardess@gmail.com ' . 'Purpose: Returns the User LogOn Name or ComputerName 'Accepts: UorC; 1=User, anything else = computer 'Returns: The Windows Networking name of the user or computer On Error Resume Next Dim NBuffer As String Dim Buffsize As Long Dim Wok As Long Let Buffsize = 256 Let NBuffer = Space$(Buffsize) If UOrC = 1 Then Let Wok = api_GetUserName(NBuffer, Buffsize) Let atCNames = Trim$(NBuffer) Else Let Wok = api_GetComputerName(NBuffer, Buffsize) Let atCNames = Trim$(NBuffer) End If End Function
André Luiz Bernardes

✔ VBA Brazil®

✔ VBA Brazil®
brazilsalesforceeffectiveness@gmail.com
Related Posts Plugin for WordPress, Blogger...
diHITT - Notícias