VBA & Macro Problems

Fix the CommandType = 0 Macro Error When Importing TXT Files in Excel

Jason MillerJason Miller Nov 13, 2026 869 views

Question details

The user needs to fix an Excel macro that fails while importing a TXT file at the CommandType = 0 assignment.

Fix the Excel CommandType = 0 Macro Error for TXT Imports
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA macro imports a TXT file using a query table or external data connection.
Observed behavior
The macro may stop on the .CommandType = 0 line when the Excel version or connection type does not support that assignment.
Before you start

Open the workbook in Excel and identify the TXT file and connection used by the macro. Enable macros only if you trust the workbook and its source.

Solution 1Recommended

Comment Out the Unsupported CommandType Assignment

Use this approach if the TXT import does not need an explicit command type.

1
Open the macro

In Excel, open Developer > Visual Basic, then find the module containing the TXT import macro.

2
Comment out the line

In the code editor, add an apostrophe before the failing line so it reads '.CommandType = 0.

3
Run and check the import

Run the macro from Developer > Macros and inspect the worksheet to confirm that the TXT data imports and refreshes as expected.

Comment Out the Unsupported CommandType Assignment
Check the results: Removing the assignment is appropriate only if the connection works correctly without it. If the import fails or returns unexpected data, review the connection settings and the rest of the macro.
Free Microsoft Office alternative

Work With Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing spreadsheets. Its Excel format compatibility helps you move everyday workbook tasks to WPS, though it does not fix an Excel-specific VBA connection error.

Open and edit Microsoft Excel XLSX and XLS filesWork with spreadsheet data in a familiar interfaceUse a free, lightweight office suiteMove everyday spreadsheet work without changing file formats
QA img-9

Frequently Asked Questions

Why does CommandType = 0 cause an Excel macro error?

Some Excel versions or connection types do not support assigning zero to CommandType. Check the object and connection used by the macro before changing the property.

Can I delete the CommandType line from my TXT import macro?

You can comment it out in Developer > Visual Basic and test the macro. Keep it removed only if the TXT data imports and refreshes correctly without the assignment.

Where can I find the connection used by the macro?

Check the query table or connection references in the VBA code, and look under Data > Queries & Connections for the associated data source.

Should I replace zero with another CommandType value?

Only if the specific connection supports and requires that command type. Consult the documentation for the connection object and test the macro in the target Excel version.