Search code examples
vbaexcelwindows-7

How to check admin privileges in vba


I have an excel macro that needs to know whether it has admin privileges. The macro is running a shell command that will fail if the user didn't choose to run excel as an admin.


Solution

  • There is a microsoft function used to determine whether the user running your application has admin privileges.

    First include the library this function resides in.

    Private Declare Function IsUserAnAdmin Lib "shell32" () As Long
    

    Then just call the function and utilize the return boolean in any way

    if IsUserAnAdmin() then
        //Ask user to run application as admin
    End if