Hello,

I am trying to use the following code to import a text file whose filepath is defined in a cell in the same workbook:

Sub ImportText()

Dim path As String
path = Range("A1").Text

With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT; & path & " _
, Destination:=Range("a3"))

.Name = "test"

.FieldNames = True
.RowNumbers = False

.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileCommaDelimiter = True

.Refresh BackgroundQuery:=False
End With
End Sub


However, I get the following error:

Run-time error '1004';
Application-defined or object-defined error


Any thoughts?

Scott