The VBA runtime error 460 (Invalid Clipboard Format) occurs when your code tries to paste data into the clipboard, but the data format stored there does not match the format your VBA code expects. This is almost always caused by a previous operation—often an external application or another piece of VBA code—changing the clipboard contents to a format your code cannot read. The fix is to ensure the clipboard is cleared or reset before pasting, or to ask Excel to convert the data to a usable format first.

What You'll Need

  • Microsoft Excel (or another Office application like Word) with the VBA editor (Alt + F11) open.
  • A code module containing code that attempts to write to the clipboard or copy data.
  • A basic understanding of the Immediate Window (Ctrl + G) for testing steps.

Step-by-Step

  1. Identify the failing line: Open your VBA project in the editor (Alt + F11). Press Ctrl + G to open the Immediate Window. Run your code and look for the line that triggers the error. It is usually an instruction like Selection.Copy, Clipboard.SetText ..., or a line that attempts to read the clipboard content.
  2. Check the clipboard content manually: Before fixing the code, identify what is currently on the clipboard. In Excel, click on any cell and press Ctrl + V. If you see garbage characters, a formatted document, or nothing at all, the clipboard is the source of the problem. If you see the correct data, the problem is likely how your code is requesting that data format.
  3. Clear the clipboard before writing: The most common cause of error 460 is that the clipboard contains a format your VBA code does not support (e.g., a rich text object when your code expects plain text). You can force a clean slate by writing a small block of code immediately before the failing line. In the Immediate Window, type the following and press Enter:
    Application.CutCopyMode = False
    This command clears the visual "marquee" around copied cells and resets the clipboard for a clean write operation.
  4. Force a plain text format: If your code copies a range of cells, the default format is often an Excel format (BIFF) that other programs might not understand. To avoid this, change the copy command to explicitly request a data format. In your VBA module, use the Value property instead of the default copy method. For example, instead of Selection.Copy, use the following code to copy the values and paste them immediately:
    Dim rng As Range
    Set rng = Selection
    Dim clipData As String
    clipData = rng.Value
    Clipboard.SetText clipData

    This ensures the data is saved as plain text, which is universally compatible and avoids format conflicts.
  5. Handle the paste operation: If your code is trying to read the clipboard to paste data into another application, you must ensure the receiving application can read the format you wrote. If you are pasting into a text editor or a web form, the Clipboard.GetText method is the safest bet. If you are pasting back into Excel, use the Values property to bypass formatting issues:
    Application.CutCopyMode = False
    Dim pastedRange As Range
    Set pastedRange = Selection
    pastedRange.Value = Clipboard.GetText

    This step bypasses the clipboard entirely and writes the data directly, skipping the error check.
  6. Test in a new workbook: Sometimes the error is caused by corruption in the current workbook's temporary files. Close your current project and create a new, blank workbook. Paste your fixed code into a new module and run it. If it works here, the issue was isolated to the old workbook's state.

Common Mistakes

  • Assuming the clipboard is empty: Many developers assume the clipboard is clean when they start a macro. It is rarely clean. External applications like browsers, PDF readers, or email clients frequently leave data on the clipboard. Always clear or check the clipboard immediately before writing to it.
  • Ignoring the Immediate Window: The Immediate Window is the fastest way to debug clipboard issues. You cannot easily inspect the clipboard from the VBA editor’s main window. Use it to run test commands like Application.CutCopyMode = False to see if the error resolves itself without rewriting the entire module.
  • Copying formatted cells: When you use the Selection.Copy command, you are copying the entire visual appearance of the cells, including fonts, colors, and borders. This creates a complex object on the clipboard that is difficult for other applications to read. Always use the .Value property to copy only the raw data.
  • Not resetting the mode: If you use the standard copy method (Selection.Copy), the Excel UI will show a moving dashed border around your cells. If you run another macro or interact with the UI before the new operation, you can cause conflicts. The Application.CutCopyMode = False line is essential to remove this visual indicator and lock the clipboard for your new operation.

Tips

  • Use the DataObject class: For more complex clipboard interactions, the DataObject class is often more reliable than using the global Clipboard object. It allows you to set and get data using specific formats explicitly. This gives you more control over how the data is stored and retrieved.
  • Check for long strings: The clipboard has a size limit. If you are copying a large amount of data, the operation might fail silently or produce an error. Keep an eye on the size of the data you are moving. If you are processing massive datasets, consider writing to a text file instead of relying on the clipboard.
  • Handle errors gracefully: Wrap your clipboard operations in a On Error Resume Next block. This allows your code to continue running even if the clipboard is locked or in an incompatible state. You can then check the Err.Number to see if the error occurred and handle it accordingly.
  • Restart Excel: If the error persists despite clearing the clipboard and changing the code, the underlying Excel instance may be in an unstable state. A simple restart of the application often resolves these types of memory or state-related issues.

Troubleshooting

If the steps above do not resolve the issue, proceed with these checks.

1. Check for conflicting macros: If you are running multiple macros in the same session, one macro might be writing to the clipboard while another is trying to read it. Ensure that your macros are designed to be run sequentially or that they explicitly clear the clipboard after every operation.

2. Verify application compatibility: If your VBA code is trying to paste data into a third-party application, ensure that application supports the format you are providing. Some applications are very strict about the data they accept. If you are unsure, try pasting the data manually to see if it works.

3. Reinstall Office: In rare cases, the issue may be a deeper corruption within the Office installation. This is a last resort, but if the error occurs in all workbooks and persists after clearing the clipboard and resetting Excel, a repair installation of Microsoft Office may be necessary.

Frequently Asked Questions

Why does the error happen?

The error occurs because the data currently on the clipboard is in a format that your VBA code cannot read or write. For example, if the clipboard contains a rich text object and your code asks for plain text, the error will be raised.

Can I prevent the error from happening?

Yes. By always using the Application.CutCopyMode = False command before writing to the clipboard, you ensure that the clipboard is in a clean state. Additionally, using the .Value property instead of the standard copy method ensures you are working with plain text.

Does this error happen in all Office applications?

While the error is most common in Excel, it can occur in Word and Outlook as well. The cause is the same: a mismatch between the data format stored on the clipboard and the format your code expects.

Is it safe to use On Error Resume Next?

Using On Error Resume Next is safe if you are handling the error explicitly. However, it is important to check the Err.Number immediately after the operation to ensure no errors actually occurred.

How do I clear the clipboard programmatically?

The most reliable way to clear the clipboard in VBA is to set Application.CutCopyMode = False. This command clears the visual copy indicator and resets the clipboard for a new write operation.

What is the difference between Clipboard.GetText and Selection.Value?

Clipboard.GetText reads the data currently stored on the clipboard. Selection.Value reads the raw data from the currently selected cells in Excel. Using Selection.Value is often safer because it bypasses the clipboard entirely and avoids format conflicts.