Comma delimited text file import to Excel failing

Beezkneez

Board Regular
Joined
Oct 23, 2008
Messages
123
Maybe its late in the day but this one is doing my head in. I have a .txt file Im seeking to import to an Excel worksheet where wierd and wonderful macros will do fascinating things to it.

But the actual text import is erroring and my brain has screamed that its after 4pm and then gone to the corner to pout.

Code:
Sub CDSGet()
Sheet4.Activate
Dim CDSFile As String
CDSFile = Sheet2.Range("B11").Value
Debug.Print CDSFile
[COLOR=blue]Set qtCDSRecordset = Sheet4.QueryTables _
    .Add(Connection:=CDSFile, _
        Destination:=Sheet4.Cells(1, 1))[/COLOR]
With qtCDSRecordset
    .TextFileParseType = xlDelimited
    .TextFileCommaDelimiter = True
    .Refresh
End With
End Sub

The Variable CDSFile picks up the filename and directory path from the cell B11 in Sheet2. The debug line confirms that is picking up cleanly.

When stepped through, the highlighted section is where I get a Runtime Error 1004, Application-defined or object-defined error.

I have a similar piece of code working in other workbooks and have hit a wall in figuring out why its not working here. Any guidance would be keenly appreciated.

NB: All worksheets quoted in the code exist, currently have no protection and are unhidden. Target import file exists in the specified location.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
If this piece of code is working good for other file, just check ....
the data is delimited in to how many columns?

I think Excel can take only upto 256 ...
 
Upvote 0
I imported the text file into Excel manually with comma delimitation and had no issue. Only 32 columns. Approx 3500 rows. No field contains more than about 50 characters.

Oh, using Excel 2003, VB 6.3.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,384
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top