VBA & Macro Problems

How to Fix Excel VBA Error 4605 or 5097 on the Paste Line

Phi Hung VoPhi Hung Vo Nov 2, 2026 870 views

Question details

The user needs to fix VBA runtime errors 4605 or 5097 that occur when a macro attempts to copy Excel cells and paste them into an Outlook email.

Fixing Excel VBA Error 4605 or 5097 on the Paste Line
Product
Microsoft Excel / Outlook
Device & OS
not provided
Scenario
Running a VBA macro to copy spreadsheet data and paste it into a generated Outlook email message.
Observed behavior
The macro execution fails on the Paste command, throwing runtime error 4605 or 5097. In some cases, it also throws a compilation error stating 'Invalid use of property' on the subroutine declaration.
Before you start

Ensure your macro security settings allow the execution of VBA code and verify that you have enabled the Microsoft Outlook Object Library reference in your VBA editor.

Solution 1Recommended

Explicitly Copy Ranges and Define Outlook Constants

Correct the VBA code by fully qualifying your Excel ranges, explicitly calling the copy method before pasting, and properly defining necessary Outlook constants.

Errors 4605 and 5097 often occur because the clipboard is empty by the time the paste command is executed, or because the Outlook object model is not properly instantiated. Fully qualifying your code prevents ambiguity between the Excel and Outlook applications.

1
Open the VBA Editor

Press ALT + F11 in Excel to open the Visual Basic for Applications (VBA) Editor.

2
Move Code to a Standard Module

Ensure your code is placed inside a standard module (Insert > Module) rather than a Worksheet or ThisWorkbook module.

3
Define Outlook Constants

Declare the required Outlook constants explicitly at the beginning of your script. For example, add the line: Const olMailItem = 0.

4
Qualify and Copy the Range

Qualify the range completely before copying. Use code like ThisWorkbook.Sheets("Sheet1").Range("A1:Z60").Copy to ensure the correct data is placed in the clipboard immediately before the Outlook paste operation.

5
Run and Verify

Run the macro again to test if the paste operation into the Outlook email completes successfully without triggering the 4605 or 5097 runtime error.

Explicitly Copy Ranges and Define Outlook Constants
Fixing the Compilation Error: If you receive a 'Compilation error: Invalid use of property' on the Sub declaration, make sure your procedure name (e.g., Sub sendEmail) does not conflict with existing VBA reserved words, properties, or methods. Renaming it to something unique like Sub CreateEmailReport() usually resolves this.
Free Microsoft Office alternative

Try WPS Office for Seamless Spreadsheet and Macro Compatibility

If you frequently encounter VBA runtime errors, object library conflicts, or overall compatibility issues in Microsoft Office, consider trying WPS Office. It offers robust support for macros and provides a lightweight, highly compatible alternative for your complex spreadsheet workflows.

Highly compatible with Microsoft Excel (.xlsx, .xlsm, .xls) file formats, ensuring your formulas and data stay intact.Advanced VBA and Macro support to automate complex spreadsheet workflows reliably.Free, lightweight, and fast to launch, keeping your system running smoothly.Familiar tabbed interface makes migrating from Microsoft Office completely effortless.
microsoft office alternative - wps office

Frequently Asked Questions

What does Excel VBA runtime error 4605 mean?

Error 4605 typically occurs when a requested method or property is not available at the current time. In the context of pasting into Outlook, it usually means the clipboard is empty, the target document area is locked, or the WordEditor object within the email hasn't fully initialized before the paste command executes.

Why am I getting a 'Compilation error: Invalid use of property' on my Sub line?

This compilation error happens when you name a macro using a reserved word or an existing property name. For example, if you name a module or a variable the same as your Sub name, VBA gets confused. Renaming your subroutine to a unique identifier will resolve this.

How do I add the Outlook Object Library reference in Excel VBA?

In the VBA Editor, click on 'Tools' in the top menu bar, then select 'References'. Scroll down the alphabetical list until you find 'Microsoft Outlook XX.X Object Library' (where XX.X is your version number), check the box next to it, and click 'OK'.