There is an error in the macro (macro: An action or a set of actions that you can use to automate tasks. Macros are recorded in the Visual Basic for Applications programming language.) that you were running. The specified method cannot be used on the specified object for one of the following reasons:
- An argument contains a value that is not valid. A common cause of this problem is trying to gain access to an object that does not exist; for example, Workbooks(5), when only three workbooks are open.
- The method cannot be used in the applied context. Specifically, some Range object methods require that the range contain data. If the range does not contain data, the method fails.
- An external error occurred, such as a failure to read or write from a file.
- A method or property cannot be used because of security settings. For example, the properties and methods of the VBE object for manipulating the Visual Basic for Applications (VBA) (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.) code that is stored in a Microsoft Office document are inaccessible by default.
To turn on trusted access to Visual Basic Projects, do the following:
- If the Developer tab is not available, do the following to display it:
- Click the Microsoft Office Button
, and then click Excel Options. - In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.
Note The Ribbon is a component of the Microsoft Office Fluent user interface.
- On the Developer tab, in the Code group, click Macro Security.

- Under Developer Macro Settings, select the Trust access to the VBA project object model check box.
For more information about how to use the method, search for the method name in Visual Basic Help (Microsoft Visual Basic Help: To get help for Visual Basic in Excel, point to Macro on the Tools menu, and then click Visual Basic Editor. On the Help menu, click Microsoft Visual Basic Help.).