你好,谢谢你的回复。现在的问题是先解决非得要按按钮才执行的问题。我想不按按钮让它自动执行。目前的状况是这样的,窗体中有2个按钮,代码窗口中是下面的语句:
Private Sub Command1_Click()
Dim GetCpu
End Sub
Public Function GetCpu() As String
On Error Resume Next
Dim TmpCode$
Dim ObjWMIService As Object, objItem As Object, colItems As Object
Set ObjWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = ObjWMIService.ExecQuery("Select * from Win32_Processor", , 48)
For Each objItem In colItems
TmpCode = TmpCode & " " & objItem.ProcessorId
Next
GetCpu = Trim(TmpCode)
End Function
Private Sub Command2_Click()
Open "F:\aa.dat" For Output As #1
Write #1, GetCpu
Close #1
End Sub
麻烦你给看看怎样去掉按钮,让它自动运行?