Heh, almost there. Now, forgetting code for a moment, show me what you would want done with this data. I'm trying simply to get what's in your mind onto a sheet where I can see it, too. Automation follows being able to see the finish line.
THe macro recorder can easily handle recording YOU doing something simple, then you're right, you have to tweak it (with our help) to make it dynamic and repeatable. That's the point of this exercise.
This code is yours, with mine derived from the macro recorder recording me actually importing that text file into a sheet. Then I edited it to use the variables you had already designed.
Option Explicit
Sub CreateWorkbook()
Dim UserFile As String, DestBook As Workbook
UserFile = Application.GetOpenFilename(FileFilter:="Text files (*.txt),*.txt", Title:="Choose the Text File", MultiSelect:=False)
If UserFile = "False" Then Exit Sub
Set DestBook = Workbooks.Add
Sheets("Sheet1").Name = "Summary"
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Data"
With Sheets("Data").QueryTables.Add(Connection:="TEXT;" & UserFile, _
Destination:=Sheets("Data").Range("A1"))
.Name = "sampleTextFile"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
With Sheets("Summary")
.Range("A1") = "Data-ColA"
.Range("A2").Formula = "=SUM(Data!$A:$A)"
End With
End Sub
Bookmarks