相关文章推荐
坏坏的海龟  ·  VBA) (Property Let ...·  2 月前    · 
帅气的山羊  ·  With statement (VBA) ...·  1 周前    · 
好帅的大蒜  ·  MySQL: ...·  6 月前    · 
好帅的饺子  ·  java ...·  1 年前    · 

Environ("computername")

2.WScript Shell Object

CreateObject("WScript.Shell").ExpandEnvironmentStrings("%COMPUTERNAME%")

3.WScript Network Object

CreateObject("WScript.Network").ComputerName

4.API方法

#If VBA7 And Win64 Then

'x64 Declarations

Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As LongPtr) As LongPtr

#Else

'x32 Declaration

Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

#End If

Function ComputerName() As String

Dim sBuff As String * 255

Dim lBuffLen As Long

Dim lResult As Long

lBuffLen = 255

lResult = GetComputerName(sBuff, lBuffLen)

If lBuffLen > 0 Then

ComputerName = Left(sBuff, lBuffLen)

End If

End Function

附   件:

Access软件网QQ交流群(群号:39785885)

Access源码网店