Query Tables Error message

Neil999

New Member
Joined
Jul 18, 2007
Messages
1
I am runnig Office/Excel 2000 on Vista, howevere the target deployment will be on XP. The problem - During the day I will receive a number (not known) of text files which I want to append to my worksheet. Having appended them to the worksheet I want to move them to a different directory so they are not imported again and I would like the Import query to be deleted. The code:

Private Sub Import_Click()
Dim MyFile As String
MyFile = Dir("C:\Users\Neil\Documents\TextImportNew\*.TXT")

Do While MyFile <> "" ' Start the loop.
ImportTextFile1 FName:=MyFile, Sep:=","
'move to different directory
Name MyFile As "C:\Users\Neil\Documnets\TextImportOld\*.txt"
MyFile = Dir 'Get next entry
Loop
End Sub

Private Sub ImportTextFile1(FName As String, Sep As String)

Dim StartRange As String
Application.ScreenUpdating = False
StartRange = "A" & 20 'This is just a range I am using to test the code

With Worksheets("Menu").QueryTables.Add(Connection:= _
"TEXT;FName", Destination:= _
Range(StartRange))
.Name = "Query1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 2
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1)
.Refresh BackgroundQuery:=False
End With

End Sub

On step through I get the following error message on the .Refresh BackgroudQuery:=False statement - Run time error 1004, Application-defined or Object-defined error.

Thanks in anticipation of your help. Neil. :(
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,215,622
Messages
6,125,886
Members
449,269
Latest member
GBCOACW

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