Skip to content

Instantly share code, notes, and snippets.

@kcchien
Last active October 3, 2018 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcchien/c45eff2d6ac1a334c14f65c8540b8761 to your computer and use it in GitHub Desktop.
Save kcchien/c45eff2d6ac1a334c14f65c8540b8761 to your computer and use it in GitHub Desktop.
VBA 取得電腦名稱及使用者名稱
' Way 1: Though environment variables
Dim sHostName As String
Dim sUserName As String
' Get Host Name / Get Computer Name
sHostName = Environ$("computername")
' Get Current User Name
sUserName = Environ$("username")
' Way 2: Through WScript Host
Dim objNetwork As Object
Set objNetwork = CreateObject("WScript.Network")
ComputerName = objNetwork.ComputerName
Set objNetwork = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment