Excelpromax123
Board Regular
- Joined
- Sep 2, 2021
- Messages
- 172
- Office Version
- 2010
- Platform
- Windows
Hello everyone. I used the following code to get the hard drive code. Normally, the code runs very well, getting results in about 0.1 seconds. But when the computer is in sleep mode after restarting, the code runs for 10 seconds to give results. So please tell me how the code does not hang after the computer is in sleep mode restart. Thank
VBA Code:
Sub text()
On Error Resume Next
Dim a As String
Set Discos = GetObject("winmgmts:\root\CIMV2").ExecQuery _
("SELECT * FROM Win32_PhysicalMedia")
For Each Disco In Discos
abc = Disco.SerialNumber
If Len(Trim(abc)) > 0 Then Exit For
Next
MsgBox (abc)
End Sub