ShovelingFishHeads
New Member
- Joined
- Jun 4, 2012
- Messages
- 5
Hi everyone!
How can I integrate the manual opening of the "Import Text Data" process into a macro?
I have a client that wants a macro that automates the process of importing data from a text file into an excel worksheet, but they are adament that the user manually opens the text file (searching around among directories) to find the specific file. Actual importation once the file is selected is to be automated.
This sounds a little strange and overly compledated I know, but the client doesn't want to do it in a simpler way.
Can I start the macro with the openning of the directory list dialogue and then have it continue once one file is double clicked? how would that look in code?
code i am using to import looks like this:
'''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''
'
'Get file data imported
'Write formulas in the next macro
'
'''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''
Sub OpenTextFile()
'
' OpenTextFile Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;G:\list.BSC", _
Destination:=Range("$A$1"))
.Name = "list"
.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 = xlFixedWidth
.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)
.TextFileFixedColumnWidths = Array(28, 4, 30, 4, 9, 16, 42, 3, 20, 18, 12, 30, 5, 11)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Any help is greatly appreciated. T H A N K S!!
How can I integrate the manual opening of the "Import Text Data" process into a macro?
I have a client that wants a macro that automates the process of importing data from a text file into an excel worksheet, but they are adament that the user manually opens the text file (searching around among directories) to find the specific file. Actual importation once the file is selected is to be automated.
This sounds a little strange and overly compledated I know, but the client doesn't want to do it in a simpler way.
Can I start the macro with the openning of the directory list dialogue and then have it continue once one file is double clicked? how would that look in code?
code i am using to import looks like this:
'''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''
'
'Get file data imported
'Write formulas in the next macro
'
'''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''
Sub OpenTextFile()
'
' OpenTextFile Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;G:\list.BSC", _
Destination:=Range("$A$1"))
.Name = "list"
.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 = xlFixedWidth
.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)
.TextFileFixedColumnWidths = Array(28, 4, 30, 4, 9, 16, 42, 3, 20, 18, 12, 30, 5, 11)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Any help is greatly appreciated. T H A N K S!!