Hi All
I have this Macro for Excel which imports 1 file C:\datafiles\user1-data-1.txt into cell E52:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 10/29/2008 by jouell
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\datafiles\user1-data-1.txt", Destination:=Range("E52"))
.Name = "user1-data-1"
.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 = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Application.Goto Reference:="Macro2"
End Sub
I'd like to be able to set the file name to import based on the name of excel file that I'm importing data to.
I.E
This piece:
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\datafiles\user1-data-1.txt", Destination:=Range("E52"))
Would become:
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\datafiles\name_of_excel_file-data-1.txt", Destination:=Range("E52"))
I.E if the Main Excel file name is CoolDoc.xls, the macro imports CoolDoc-data1.txt.
Thanks!
-jouell
Bookmarks