Hi,

I wanted to write a macro, that imports a certain text file.

I am using the following code, which prompts a certain error like object not defined

MsgBox ("Choose adhoc File"):
updatefilename = Application.GetOpenFilename
'Set adhocBook = Workbooks.filepath
Set mainbook = ActiveWorkbook

Workbooks.Open (updatefilename)


adhocpath = Application.ActiveWorkbook.FullName

mainbook.Activate


'
Sheets("adhoc1").Select

    With ActiveSheet.QueryTables.Add(Connection:= _
        " & adhocpath & ", Destination _
        :=Range("$A$1"))
        .Name = "ADHOC"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 65001
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
i have italicized on which line the error is coming.

Thank You,
Bharat