Running code hangs after computer is in sleep mode

Excelpromax123

Board Regular
Joined
Sep 2, 2021
Messages
167
Office Version
  1. 2010
Platform
  1. 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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,215,474
Messages
6,125,024
Members
449,204
Latest member
LKN2GO

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top