2
votes

I have an Excel macro enabled workbook saved in a trusted location. I am trying to open that workbook and run the macro from Outlook.

Sub run_Excel_Macro()
    Dim App As Excel.Application
    Dim wkbk As Excel.Workbook

    Set App = New Excel.Application
    App.Visible = True
    Set wkbk = App.Workbooks.Open("C:\file.xlsm")
    App.OnTime DateAdd("s", 5, Now()), wkbk.Name & "!macro"

    Set App = Nothing
    Set wkbk = Nothing
End Sub

The issue that I am running into is that Excel's security notice pops up asking if I trust the content and whether or not macros should be enabled.

Why is the security notice poping up? How can I get around this issue?

1
Are you sure all files are in the trusted folder and the trust settings are set correctly?Chrismas007
@Chrismas007 I can manually open the Excel file and run the macro without getting a security notice. I also have Outlook macros that run without getting a security notice.Degustaf
Did the solution below end up working for you?Chrismas007

1 Answers

2
votes

One option would be to create a Digital Signature for your macro: https://support.office.com/en-ca/article/Digitally-sign-your-macro-project-956e9cc8-bbf6-4365-8bfa-98505ecd1c01

Because a digital certificate that you create isn't issued by a formal trusted certificate authority, macro projects that are signed by using such a certificate are known as self-signed projects. Microsoft Office trusts a self-signed certificate only on a computer that has the self-signing certificate added to the Trusted Root Certification folder in the Certificates - Current User store.

Create a self-signing certificate Windows 7, Windows Vista, or Windows XP

  • Click Start, point to All Programs, click Microsoft Office, click Microsoft Office Tools, and then click Digital Certificate for VBA Projects.
  • The Create Digital Certificate dialog box appears.
  • In the Your certificate's name box, type a descriptive name for the certificate.
  • Click OK.
  • When the SelfCert Success message appears, click OK.

Create Digital Signature dialog View the certificate by using Internet Explorer

To view the certificate in the Personal Certificates store, do the following:

  • Open Internet Explorer.
  • On the Tools menu, click Internet Options, and then click the Content tab.
  • Click Certificates, and then click the Personal tab.

Digitally sign a macro project in Excel, PowerPoint, Publisher, Visio, or Word

  • Open the file that contains the macro project that you want to sign.
  • On the Developer tab, in the Code group, click Visual Basic.
  • In Visual Basic, on the Tools menu, click Digital Signature.
  • The Digital Signature dialog appears.
  • Select a certificate and click OK.

Note If you haven't selected a digital certificate or want to use another, click Choose. Select a certificate and click OK.

Notes

  • It is recommended that you sign macros only after your solution has been tested and ready for distribution: when code in a signed macro project is changed in any way, its digital signature is removed. However, if you have the valid digital certificate that was previously used to sign the project on your computer, the macro project is automatically re-signed when you save it.

  • If you want to prevent users of your solution from accidentally changing your macro project and invalidating your signature, lock the macro project before you sign it. Your digital signature implies that you guarantee the project has not been tampered with since you signed it. Your digital signature does not prove that you wrote the project. Therefore, locking your macro project doesn't prevent another user from replacing the digital signature with another signature. Corporate administrators can re-sign templates and add-ins so that they can control what users run on their computers.

  • If you create an add-in that adds code to a macro project, your code should determine if the project is digitally signed and should notify the users of the consequences of changing a signed project before they continue.

  • When you digitally sign macros, it is important to obtain a time stamp so that other users can verify your signature if the certificate used for the signature has expired, or has been revoked after signing. If you sign macros without a time stamp, the signature remains valid during the validity period of your certificate.