macro for importing text files

punter21

New Member
Joined
Jan 16, 2014
Messages
17
Below is a macro I recorded for importing the text file AJ9285 into excel from an external location.
I would like to modify it so that excel will give me a prompt and I can type the text file name in.
Could you kindly help me out please? Thanks


Sub adt()
'
' adt Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;Z:\AJ9285.ADT", _
Destination:=Range("$Z$13"))
.Name = "AJ9285"
.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, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(8, 25, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 _
, 10, 10, 8, 12)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("AB:AP").Select
Selection.Delete Shift:=xlToLeft
Range("AE13").Select
ActiveCell.FormulaR1C1 = "1"
Columns("AC:AC").Select
Selection.Delete Shift:=xlToLeft
Range("AD14").Select
ActiveCell.FormulaR1C1 = "2"
Columns("AD:AD").Select
Selection.Delete Shift:=xlToLeft
Range("AC20").Select
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
Sub adt()
fname = inputbox("Enter file name without path and extension")
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;Z:\" & fname & ".ADT", _
        Destination:=Range("$Z$13"))
        ........
 
Upvote 0

Forum statistics

Threads
1,214,972
Messages
6,122,530
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top