I am working with Excel 2007 and writing a macro that needs to read some text files into excel and work on them. When I used an iterative process to input text files, my macro crashed and the error is at this line
" .Refresh BackgroundQuery:=False"
If I comment out "Do Until" loop I can intake them one by one and there is no problem.
I am wondering if any one could possible guide me through this;
Kind Regards
-------------------------------------------------------------------------
Sub Prt()
Dim Bookmark1 As String
Dim Bookmark2 As String
Dim Bookmark3 As String
K = 3
Do Until Sheets("Contents").Cells(K, 2) = "END"
Bookmark1 = Sheets("Contents").Cells(3, 3)
Bookmark2 = Sheets("Contents").Cells(3, 4)
Bookmark3 = Sheets("Contents").Cells(3, 5)
'To Open External Text File and Store it in a New worksheet
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Row" & Bookmark1
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\mehdi\Desktop\My excel Education\Document1.txt", Destination:= _
Range("$A$1"))
.Name = Document1
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.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)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With