Skip to content

Instantly share code, notes, and snippets.

@janhajk
Created September 13, 2017 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janhajk/87bb61b665f183fccbcfddbc19f4a9c3 to your computer and use it in GitHub Desktop.
Save janhajk/87bb61b665f183fccbcfddbc19f4a9c3 to your computer and use it in GitHub Desktop.
VBA get Battery Life Percentage
Private Type SYSTEM_POWER_STATUS
ACLineStatus As Byte
BatteryFlag As Byte
BatteryLifePercent As Byte
Reserved1 As Byte
BatteryLifeTime As Long
BatteryFullLifeTime As Long
End Type
Private Declare Function GetSystemPowerStatus Lib "kernel32" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long
Private Sub GetBatteryStatus()
Dim SPS As SYSTEM_POWER_STATUS
GetSystemPowerStatus SPS
Dim i%
i = SPS.BatteryLifePercent
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment