excelvbaexcel-2013security-warning

What are the differences between the microsoft excel security notice popup and the message bar in excel 2013?


I am encountering an issue developping a VBA functionality in an excel Workbook. This workbook is geared toward being used by end-users without administration rights, who need to activate the macros on this specific workbook before being able to use it.

To this end, I have done the following:

This enables to:

' Code to hide temporary ws and show target ws

Private Sub setTargetVisibility()

    Dim ws As Excel.Worksheet
    
    ThisWorkbook.Activate
    
    Set ws = ThisWorkbook.Sheets(getParm("tempHomeWSName"))
    With ws
        .Visible = xlSheetVeryHidden
    End With
    
    Set ws = ThisWorkbook.Sheets(getParm("homeWSName"))
    With ws
        .Visible = xlSheetVisible
        .Activate
    End With

End Sub

This works fine most of the time, because the users get prompted to activate the macro through the message bar:

message bar

However, they sometimes get another prompt to activate the macros: a microsoft excel security notice popup. Whenever they activate the macro through this popup, they get a runtime error 1004 (e.g. the method Activate of the _workbook object failed), in the sub with the code above.

enter image description here

Edit: an important thing to note is that this excel file is opened in Protected view as it is generated by a web application and downloaded by the user before use.

What cause these different way of enabling macro in excel 2013 (message bar vs. popup)? What are the behaviour differences between them?

Thanks in advance.

Regards,


Solution

  • By default, when you first open a macro-enabled workbook you’ll see a yellow “SECURITY WARNING” bar appear just underneath the ribbon. Clicking the “Enable Content” button will enable macros.

    If the Visual Basic Editor is open at the time you are opening the file with macros, the Microsoft Excel Security Notice will be displayed.