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.
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.