When you open a workbook that contains macros, you might see a security warning, at the top of the worksheet, above the Formula Bar.If you copy VBA code into your Excel file, you might need to make changes to the object names, or other settings, so that the code works correctly in your file.

To stop the code, click the Run menu, then click Reset.

Change the sheet name in the line that was highlighted, save the changes, and try the code again.

If the code refers to objects on the worksheet, be sure to add those objects in your workbook, and use the correct object name in the code.

Tips for copying VBA code to a workbook, and checking the code, to ensure that it runs without errors.

NOTE: If you're using an older version of Excel, click here for the Excel 2003 instructions for copying code to a workbook.

Instead of starting from scratch, if you need an Excel macro, you can often find sample code at reputable sites on the internet.

To copy that code, and add it to one of your workbooks, follow these steps: Another type of Excel code is Event code, which runs automatically when something specific occurs in the workbook.

For example, if you enter a number in a cell, or select an entry in a cell's drop down list, the worksheet has been changed. Worksheet event code is stored on a worksheet module.

To add worksheet event code to your worksheet, do the following: To use macros in Excel, you might need to enable them when the file opens.