Error when calling Word from Excel: The macros in this project are disabled

Viewed 4018

I have VBA code in Excel that calls a Word file in a specified local folder.

For some users it turns the following error:

The macros in this project are disabled. Please refer to the online help or documentation of the host application to determine how to enable macros

The error appears as the code is supposed to move from Excel to the Word file.

What I've tried so far:
Excel Trust Center:

  • The entire location (including subfolders are trusted).
  • "Allow documents on a network to be trusted" is checked.
  • Disable all macros with notification is "checked".
    I cannot change this as it is greyed out. However, this setting is the same for all users.
  • Protected view is disabled.

Word Trust Center

  • Protected view is disabled.
  • Opening the Word file doesn't produce any "enable macros" notifications.
2 Answers

The normal way to grey that out on purpose (maybe your users' IT sets this through gpo?) is a registry key, where 16.0 is the version you have installed

[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\Security]
"VBAWarnings"=dword:00000001

Some other things to troubleshoot:

  • Can they create and run their own macro?
  • Can they run a different macro in a different document?
  • Does anyone have a different version of Excel?
  • Are the excel and word file both local to the user PC?
  • Do the users have Developer settings enabled?
  • Does anyone have different settings in Macro Settings > Developer Macro Settings?
  • Is Windows blocking the excel file? Right-click the file > properties > General:

blocked

There's also this specific GPO that only blocks macros from the loosely-defined "Internet"

I had a similar issue some time ago. When opening a word document from within an Excel macro, everything worked fine for me. But on another PC, the macro simply stopped with a message indication that macros where disabled.

The issue could be solved by changing the Application.AutomationSecurity property for the word app to msoAutomationSecurityLow.

It is important to set that property back to its original value after code execution.

You can try the following code example.

Option Explicit

Sub OpenWordsFilePathWithLowSecuritySettings()
    Dim sFilePath As String
    Dim wrdApp As Object
    Dim wrdDoc As Object
    Dim lAutomationSetting As Long
    
    'The path to your word file
    sFilePath = "C:\Users\micha\Desktop\example file.docx"

    Set wrdApp = CreateObject("Word.Application")
    
    wrdApp.Visible = True
    
    'Save word app automation security so we can restore it afterwards
    lAutomationSetting = wrdApp.AutomationSecurity
    'Error handling to make sure the automation security is reset even if an error occurs
    On Error GoTo ErrorHandler
    'Change the automation setting to low security
    wrdApp.AutomationSecurity = msoAutomationSecurityLow
    
    'Open word document
    Set wrdDoc = wrdApp.Documents.Open(sFilePath)
    
    'Your code - do something with the word file
    '
    '
    '
    
ErrorExit:
    On Error Resume Next
    'Close the word document
    wrdDoc.Close
    'Reset the word automation security
    wrdApp.AutomationSecurity = lAutomationSetting
    wrdApp.Quit
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
    
    Exit Sub
    
ErrorHandler:
    MsgBox "An error occured: (Code: " & Err.Number & ", Description: " & Err.Description & ")", vbCritical, "Error"
    Resume ErrorExit
End Sub
Related