Saberexcel - o site das macros
Estas macros com as declarações e funções do Aplicativo Microsoft Excel VBA, retornam o nome do usuário e o nome do máquina
Option Explicit
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Function OSUserName() As String
Dim Buffer As String * 256
Dim BuffLen As Long
BuffLen = 256
If GetUserName(Buffer, BuffLen) Then _
OSUserName = Left(Buffer, BuffLen - 1)
End Function
'.................................'
Function OSMachineName() As String
Dim Buffer As String * 256
Dim BuffLen As Long
Dim lngX As Long
Dim strCompName As String
BuffLen = 255
If GetComputerName(Buffer, BuffLen) Then _
OSMachineName = Left(Buffer, BuffLen)
End Function
'.................................'
Sub Teste_Usuário_host()
MsgBox OSUserName & ” ” & OSMachineName
End Sub
'.................................'