相关文章推荐
坏坏的海龟  ·  VBA) (Property Let ...·  1 周前    · 
坚强的围巾  ·  svn lock ...·  1 年前    · 
阳刚的饭盒  ·  Effective ...·  1 年前    · 
忐忑的风衣  ·  小爱同学关灯,OK ...·  1 年前    · 
坚强的领带  ·  Win10 ...·  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源码网店