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:
- I created a "temporary home worksheet" which asks the user to activate the macros (no code, a simple message in the cells of this worksheet), which is initially visible
- I created a "home worksheet" which is initially (very) hidden, and which holds buttons and other controls that can be used
- I wrote a simple sub which is called:
- when the workbook is opened and the activesheet is the "temporary home worksheet"
- or when the "temporary home worksheet" is activated
- This sub does the following (see code below):
- hide the "temporary home worksheet" (to very hidden)
- show the "home worksheet"
This enables to:
- show a message asking the user to activate the macros if he/she has not done it
- redirect to the target "home worksheet" if the user activate the macros while the "temporary home worksheet" is activated
- redirect to the target "home worksheet" if the macros are activated and the user activates the "temporary home worksheet"
' 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:
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.
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,