VBA & Macro Problems

How to Fix VBA Error When Importing Data from an External Workbook

John WilsonJohn Wilson Oct 28, 2026 868 views

Question details

The user encounters a run-time error when running a VBA macro designed to copy data from an external workbook and paste it into a new worksheet.

How to Fix VBA Error When Importing Data from an External Workbook
Product
Excel
Device & OS
not provided
Scenario
Executing a VBA macro to open an external Excel file, extract data, and paste it using the PasteSpecial method into another worksheet.
Observed behavior
The macro fails to complete the pasting process, throwing either run-time error 9 (Subscript out of range) or run-time error 438 (Object doesn't support this property or method).
Before you start

Before modifying your VBA code, verify that the external workbook is accessible and save a backup copy of your current macro-enabled workbook.

Solution 1Recommended

Correct the PasteSpecial Syntax and Object References

Fix missing spaces in the PasteSpecial statement and ensure your workbook and worksheet names are correctly spelled to resolve run-time errors 438 and 9.

Run-time error 438 often occurs due to a typo in the VBA code, particularly when a method and its parameters lack a separating space. Run-time error 9 indicates that the macro is trying to access a worksheet or workbook name that does not exist.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.

2
Locate the PasteSpecial Statement

In the project explorer, double-click the module containing your import macro and locate the line utilizing the PasteSpecial method.

3
Insert the Missing Space

Check the PasteSpecial syntax. If it is written as 'PasteSpecialxlPasteValues', insert a space between the method and argument so it reads exactly as 'PasteSpecial xlPasteValues'.

4
Verify Worksheet Qualifications

Review your object references. Ensure that 'ThisWorkbook.Worksheets("Sheet1")' perfectly matches the exact name of the destination sheet in your workbook.

5
Save and Run

Click the Save icon, close the VBA editor, and run your macro again to confirm the data imports successfully without errors.

Correct the PasteSpecial Syntax and Object References
Syntax Resolved: Adding the space correctly formats the argument, resolving the object property error (438) and allowing the paste action to execute.
Seamless Macro Support

Edit and Run VBA Macros Seamlessly in WPS Office

WPS Office provides robust compatibility with Excel workbooks, including those with macros. You can easily open your macro-enabled files, troubleshoot VBA syntax errors in the built-in editor, and execute your data imports flawlessly.

  1. 1. Open Your Workbook: Launch WPS Office Spreadsheet and open your macro-enabled Excel workbook.
  2. 2. Access the Developer Tab: Navigate to the 'Developer' tab on the top ribbon and click on 'Macros' or 'Visual Basic' to launch the code editor.
  3. 3. Edit Your VBA Code: Find your target module, fix the missing space in the PasteSpecial command, and ensure your worksheet references are accurate.
  4. 4. Execute the Macro: Run the macro directly within WPS Office to successfully copy and paste the external data.
Fully compatible with Microsoft Excel .xlsm and .xlsb formatsBuilt-in Macro editor for writing, editing, and debugging VBA codeLightweight architecture for fast data processing and importingFamiliar user interface requiring no steep learning curve
microsoft office alternative - wps office

Frequently Asked Questions

What does run-time error 9 'Subscript out of range' mean in VBA?

This error occurs when VBA attempts to access a workbook, worksheet, or array element that does not exist. During data imports, it usually means the worksheet name specified in the code (e.g., 'Sheet1') is misspelled, deleted, or does not exist in the referenced workbook.

Why do I get run-time error 438 with the PasteSpecial method?

Error 438 'Object doesn't support this property or method' happens due to incorrect syntax. If you omit the space between 'PasteSpecial' and its argument (like writing 'PasteSpecialxlPasteValues'), Excel misinterprets the entire string as a single, non-existent property.

How do I properly qualify a worksheet object when importing data?

To properly qualify a worksheet, you must explicitly declare which workbook it belongs to. Use a full reference like `Workbooks("ExternalData.xlsx").Worksheets("Data")` instead of just using `Range("A1")`, which defaults to the currently active sheet and can cause pasting into the wrong file.