An Excel spreadsheet needs programmatic access to its Project
structure. However, this access is disabled by default. It can be enabled programmatically, by writing to the registry with this snippet:
Set wsh = CreateObject("WScript.Shell")
'key to modify'
str1 = "HKEY_LOCAL_MACHINE\Software\Microsoft\Office\" & Application.Version & "\Word\Security\AccessVBOM"
'enable access'
wsh.RegWrite str1, 1, "REG_DWORD"
'read the vba project name'
MsgBox Application.NormalTemplate.VBProject.Name
'disable access'
wsh.RegDelete str1
Although it can be done (and reset) programmatically, this could create a security issue.
In my project, it attempts to modify the Project
structure, and throws an error if it cannot. The error can be caught, and at this point it can either run the snippet to enable access or display an error message to the user to enable access manually. Is it better to enable the access via the program, where it can be disabled later, or instruct the user to do so?