Automate text import

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I'm new to writing macros, and I've been asked to write a macro that imports colon delimited text files into excel. I need to create the macro so that the user is prompted for the file to import. I used the macro recorder, but I cannot get it to work using a variable. Can anyone lend a hand

-Jamie
 
Jami

Is this the type of thing that you mean

Ton

getfilename = InputBox("Enter the file name including path", , "c:\temp\aaa.txt"
Workbooks.OpenText FileName:=getfilename, Origin:=xlWindows,
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False
, Space:=False, Other:=True, OtherChar:=":", FieldInfo:=Array(Array(1, 1
), Array(2, 1), Array(3, 1)

----- Jamie Abbamont wrote: ----

Hi. I'm new to writing macros, and I've been asked to write a macro that imports colon delimited text files into excel. I need to create the macro so that the user is prompted for the file to import. I used the macro recorder, but I cannot get it to work using a variable. Can anyone lend a hand

-Jamie
 
Jamie

Try this version

Gives user normal Open file dialog box


Sub OpenFile()
Dim sFile As String

sFile$ = Application.GetOpenFilename("Text Files (*.*),*.txt")
If sFile = "False" Then
End
End If
Workbooks.OpenText FileName:= _
sFile, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True
_
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2,
1), _
Array(3, 1), Array(4, 1))
End Sub
 
Back
Top