Getting computer name using VBA

后端 未结 3 517
暗喜
暗喜 2020-12-13 08:40

Is there a way to get the name of the computer in VBA?

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 09:32

    You can do like this:

    Sub Get_Environmental_Variable()
    
    Dim sHostName As String
    Dim sUserName As String
    
    ' Get Host Name / Get Computer Name    
    sHostName = Environ$("computername")
    
    ' Get Current User Name    
    sUserName = Environ$("username")
    
    End Sub
    

提交回复
热议问题