Microsoft KB Archive/824007

From BetaArchive Wiki

Article ID: 824007

Article Last Modified on 1/5/2007



APPLIES TO

  • Microsoft Office Excel 2003
  • Microsoft Visual Studio Tools for the Microsoft Office System version 2003



SYMPTOMS

When you start Microsoft Office Excel, and you open a workbook that uses a managed code extension, you may receive a message similar to the following:

Macros are disabled because the security level is set to High and a digitally signed Trusted Certificate is not attached to the macros. To run the macros, change the security level to a lower setting (not recommended), or request the macros be signed by the author using a certificate issued by a Certificate Authority.

The workbook then opens in Design Mode, and any managed code event handlers for Microsoft ActiveX controls in the workbook will not run.

CAUSE

This behavior occurs when the following are true:

  • The macro security level in Excel is set to High.


-and-

  • The workbook contains a Microsoft Visual Basic for Applications (VBA) project that has not been digitally signed.

When the macro security level is set to High, any workbook that contains a VBA project that has not been digitally signed must open in Design Mode.

WORKAROUND

To work around this behavior, use one of the following methods.

Method 1: Add a Digital Signature to the Macro

Excel runs macros that are signed by a trusted source. Obtain a digital signature, and then add the digital signature to the macro. To add the digital signature:

  1. Open the file that contains the macro project that you want to sign.
  2. On the Tools menu, point to Macro, and then click Visual Basic Editor.
  3. In Project Explorer, click the project that you want to sign.
  4. On the Tools menu, click Digital Signature.
  5. Click Choose, click the certificate, and then click OK. Click OK again to close the Digital Certificate dialog box.

Method 2: Change the Macro Security Level

To change the macro security level:

  1. On the Tools menu, click Options.
  2. Click the Security tab.
  3. Under Macro Security, click Macro Security, and then click the Security Level tab.
  4. On the Security Level tab, click the security level that you want to use, and then click OK two times.

For more information about macro security, click Microsoft Excel Help on the Help menu. Type about macro security in the Search text box of Assistance. Click Search.

Method 3: Remove the VBA Code from the Workbook

If the functionality that your VBA code provides has a managed code equivalent, you can transition this functionality to the managed code extension. After you have transitioned the code, you can remove all the modules and code that the workbook's VBA project contains.

When you use this method, you avoid the security warning and the workbook does not open in Design Mode when the Excel macro security level is set to High. If you cannot completely remove the VBA project from your workbook, you can move only the worksheets in the workbook to a new workbook.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Excel workbook project:
    1. Start Visual Studio .NET 2003.
    2. On the File menu, click New, and then click Project.
    3. Under Microsoft Office System Projects, click Visual Basic Projects, and then click Excel Workbook.
    4. Click OK to start the Microsoft Office Project Wizard.
    5. Click Create new document, and then click Finish.
    6. In the code window, locate the following code:

      ' Called when the workbook is opened.
      Private Sub ThisWorkbook_Open() Handles ThisWorkbook.Open
      
      End Sub

      Replace this code with the following code:

      ' Called when the workbook is opened.
      Friend WithEvents btn As MSForms.CommandButton
      Private Sub ThisWorkbook_Open() Handles ThisWorkbook.Open
          MessageBox.Show("The Open Event Fired.")
          btn = Me.FindControl("CommandButton1")
      End Sub
    7. In the code window, paste the following code in the class module:

      Private Sub btn_Click() Handles btn.Click
              MessageBox.Show("Click")
      End Sub
    8. Press F5 to build and then run the project.

      The workbook opens in Excel and a message box appears. Click OK to close the message box.
  2. In Excel, point to Toolbars on the View menu, and then click Control Toolbox.
  3. Add a Command Button to the workbook.
  4. On the Tools menu, point to Macro, and then click Security.
  5. Click the Security Level tab, click High, and then click OK.
  6. Click Tools, point to Macro, and then click Visual Basic Editor.
  7. On the Insert menu, click Module.
  8. Paste the following code in the module:

    Sub a() 
        MsgBox "Hello" 
    End Sub 
  9. On the File menu, click Close and Return to Microsoft Office Excel.
  10. Save your changes to the workbook, and then quit Excel.
  11. Restart Excel, and then open the workbook.

    The security message appears.
  12. Click OK to close the message box.

    The message box from the Open event handler appears.
  13. Click OK to close the message box.

    The workbook opens in Design Mode.
  14. Click CommandButton1.

    Notice that the managed code event handler does not run.


REFERENCES

For additional information about how to obtain and use digital signatures, click the following article numbers to view the articles in the Microsoft Knowledge Base:

217221 OFF2000: Using SelfCert to Create a Digital Certificate for VBA Projects


206637 OFF2000: Overview of Digital Certificates



Additional query words: prb OfficeErrorMessages 10049 XL2003

Keywords: kbprb KB824007