1. Make a backup of your workbook.
2. Open your workbook and ALT+F11
3. Locate your Workbook name in Project Explorer Window
4. Right click on your workbook name > Insert > Module
5. Copy paste the Macro code given and change the bold lines as per your requirement
6. Go back to your Workbook and ALT+F8 to display Macro Window
7. Run your Macro from here
8. Delete you Macro if the Macro was needed to be run only once.
9. Otherwise save your file as .xlsm if you intend to reuse Macro again.
Sub GetBatteryStatus() Dim BatteryStatusCode As Long Dim Arr(1 To 11) Arr(1) = "The battery is discharging." Arr(2) = "The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging." Arr(3) = "Fully Charged" Arr(4) = "Low" Arr(5) = "Critical" Arr(6) = "Charging" Arr(7) = "Charging and High" Arr(8) = "Charging and Low" Arr(9) = "Charging and Critical" Arr(10) = "Undefined" Arr(11) = "Partially Charged" Dim Obj As Object For Each Obj In GetObject("winmgmts:").InstancesOf("Win32_Battery") BatteryStatusCode = Obj.BatteryStatus Next Obj MsgBox "Batter Charging Status: " & Arr(BatteryStatusCode) End Sub