Last active
October 3, 2018 06:48
-
-
Save kcchien/c45eff2d6ac1a334c14f65c8540b8761 to your computer and use it in GitHub Desktop.
VBA 取得電腦名稱及使用者名稱
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' 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