VBAEnabled: Did User Click “Enable Contents”?

With Excel, users have to click “Enable Contents” when they first open a file with VBA embedded. This function allows you to check if they did so.

VBAEnabled

Function VBAEnabled(Optional TrueString As String = "") As String
    Application.Volatile
    VBAEnabled = TrueString
End Function
ParameterDescription
TrueStringOptional text that will be displayed in the cell this function is put into when VBA is enabled.

Examples

=IFERROR(VBAEnabled("VBA Enabled"), "VBA Disabled")

If you place the above formula into cell A1, that cell shows:

  • VBA Enabled: If VBA is enabled – e.g. user clicked “Enable Contents” when file was opened, file was placed in a trusted location.
  • VBA Disabled: If VBA is not enabled – e.g. user didn’t click “Enable Contents when file was opened, file was not placed in a trusted location.

Consider changing “VBA Enabled” (i.e. TrueString parameter) to a blank alongside IFERROR if you’d only like Excel to show a message when VBA is disabled.

Scroll to Top