vba sistema o nome do usuário e o nome do computador

Sáb, 27 de Novembro de 2010 19:56 Escola Saberexcel VBA
Imprimir



Retorna o nome do usuário e nome máquina
Saberexcel - Dicas microsoft Excel VBA

Estas macros com as declarações e funções retorna o nome do usuario 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

Sub Teste_Usuario_host()
MsgBox "Usuário: [" & Nome_Usuario & "] e " & "Nome da Máquina [" & Nome_Maquina & " ]", _
vbInformation, "Saberexcel - o site das macros"
End Sub

Function Nome_Usuario() As String
Dim Buffer As String * 256
Dim BuffLen As Long
BuffLen = 256
If GetUserName(Buffer, BuffLen) Then _
Nome_Usuario = Left(Buffer, BuffLen - 1)
End Function

Function Nome_Maquina() 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 _
Nome_Maquina = Left(Buffer, BuffLen)
End Function



Aprenda tudo sobre o Aplicativo Microsoft Excel VBA

 

 

 

 

 

Tags: