I have seen several questions relating to Object variable not set when using Activeworkbook, but none for my particular scenario. I use some code in workbook_open that tests a condition to decide if the user should be shown a form
If Len(ActiveWorkbook.Names("DCStype_Selected").RefersToRange.Value) = 0 Then
This works fine for most users 99% of the time. However some users have reported error 91 - Object Variable or with block variable not set, and it is on the activeworkbook line.
I believe I have tracked the scenario where this happens and it is always for users who do not have my excel workbook in a trusted location, and so are prompted to enable macros and this error occurs when they click the "enable" button.
Once I have talked them through setting a folder as a trusted location, and moving the workbook to that folder, this issue does not occur.
Could anyone tell me a more defensive way to code my line, so that it works regardless of a users security settings?
Could some one explain why this error only occurs in this specific scenario?