vba统计电脑计算机名和登陆的用户名
Public Sub GetIPT() gipt = Trim(InputBox("请输入所在组,只需输入前面的字母代码即可 A- groupA B-groupB C-groupC D-groupD E-groupD ")) strIPT = UCase(gipt) If strIPT = "A" Then GetInfo ("AirBus"): End If strIPT = "B" Then GetInfo ("Boeing"): End If strIPT = "C" Then GetInfo ("Engines"): End If strIPT = "D" Then GetInfo ("Bombarbier"): End If strIPT = "E" Then GetInfo ("BJ"): End End Sub Function GetInfo(IPT As String) Dim TheName As String On Error GoTo line1 computername = Environ("Computername") UserName = Environ("Username") rw = Sheet1.Range("a65536").End(xlUp).Row i = 0 i = i + rw Sheet2.Cells(i, 1) = computername Sheet2.Cells(i, 2) = UserName Sheet2.Cells(i, 3) = IPT Sheet2.Copy TheName = ThisWorkbook.Path & "./" & computername & ".xls" ActiveWorkbook.SaveAs Filename:=TheName, FileFormat:=xlNormal Sheet2.Range("A1:C65536").ClearContents MsgBox "信息已采集完," & computername & ".xls 文件已生成" ActiveWorkbook.Close line1: End Function