7
votes

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
Hi, did you find a fix? I'm having the same issue.Griffin
Perhaps you can make the VBA code a add-in, that way it's more connected to the Excel instance than the workbook/document. Is that a possible solution? @GriffinAndreas
When you say "The error appears as the code is supposed to move from Excel to the Word-file", should we understand that there is a piece of code from a document (.docm type), or in Normal.dotm? Or, the excel code does only manipulate documents in a Word session?FaneDuru
This may be due to the enable macro option, try to integrate this to your excel so macro will be automatically enabled xl-central.com/force-users-to-enable-macros-in-a-workbook.htmlVignesh
Some of the questions posed in @user19702 's answer are valid ones. Specifically, you need to provide more detail about each of the user's MS Office and Windows environments. Are some running 32-bit and others running 64-bit? Are some running Office 2013 and others running 2016 or 2019 or 365? Are some running C2R and others running MSI? These are things you must clarify in situations like this.MBB70

2 Answers

0
votes

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"

0
votes

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