'API 声明:
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'定义函数
Public Function ComputerName() As String
Dim Tmpstr As String
Dim l As Long
Tmpstr = String(256, 0)
l = GetComputerName(Tmpstr, 256)
ComputerName = Left(Tmpstr, InStr(1, Tmpstr, vbNullChar) - 1)
End Function
'窗体单击事件 print 计算机名
Private Sub Form_Click()
Print ComputerName
End Sub
本文介绍了一个使用VBA编写的简单示例,该示例通过调用Windows API函数GetComputerName来获取并打印当前计算机的名称。此代码适用于需要在Windows环境下运行的应用程序。
3486

被折叠的 条评论
为什么被折叠?



