c_rahul001
New Member
If i want to import text file using VBA or Macro i can use below code
Fname = Application.GetOpenFilename("Text Files (*.txt),*.txt", , _
"Select Text Data File")
but does not work if we need to perform few steps Under file origin section after opening the file using above code. Is there any other way to import file and then macro should perform few task Under file origin section of Text Import Wizard under Data tab.
I want macro to select file which user want and then perform few task on the file selected.
I have recorded a macro which select the file directly and i have no option of selecting a file which i want. However it process the code with the output but need to change the path for every time when i execute the macro for other file. Below is the code for same.
Sub Macro1()
'
' Macro1 Macro
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:RahulZh....ZS Re...2012May 20122012.05.0720111231003.txt" _
, Destination:=Range("$A$1"))
.Name = "20111231003"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 936
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Fname = Application.GetOpenFilename("Text Files (*.txt),*.txt", , _
"Select Text Data File")
but does not work if we need to perform few steps Under file origin section after opening the file using above code. Is there any other way to import file and then macro should perform few task Under file origin section of Text Import Wizard under Data tab.
I want macro to select file which user want and then perform few task on the file selected.
I have recorded a macro which select the file directly and i have no option of selecting a file which i want. However it process the code with the output but need to change the path for every time when i execute the macro for other file. Below is the code for same.
Sub Macro1()
'
' Macro1 Macro
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:RahulZh....ZS Re...2012May 20122012.05.0720111231003.txt" _
, Destination:=Range("$A$1"))
.Name = "20111231003"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 936
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub