I don't really know VBA but am trying to figure out enough to create automation for importing text files into an existing workbook. I recorded a macro and tried to decipher the code, but where I am stuck has to do with wanting a different file name each time. I want to specify which file to import, yet have the rest of the work done for me. Is there a general name to specify a text file? I saw somewhere that GetOpenFilename might be a function to use, but how? This is what the macro recorder did:
Code:
Sub ImportEval()
'
' ImportEval Macro
' Macro recorded 3/31/2009 by BJ
'
' Keyboard Shortcut: Ctrl+e
'
Sheets("Sheet1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;F:\Performance Eval Grids\Pro Co Serv Eval_NM.txt", _
Destination:=ActiveCell)
.Name = "Pro Co Serv Eval_NM"
.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 = 4
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierNone
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.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, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveCell.Offset(0, 9).Range("A1:Y1").Select
Selection.Copy
Sheets("Grading Grid").Select
Last edited by a moderator: