Text Import Wizard

  • Thread starter Thread starter Michael May
  • Start date Start date
M

Michael May

Does anyone know how I can format a .txt file (using Text
IMport Wizard) using a macro to open the file. I want to
use the following code

ChDir "H:\"Workbooks.OpenText FileName:="H:\821601 Jan
04.txt", Origin:=xlWindows, StartRow:=1,
DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array
(10 , 1), Array(21, 1), Array(52, 1), Array(62, 1), Array
(105, 1), Array(117, 1), Array(135, 1), Array(157, 1))


but rather than opening a specific file I want to use

Application.Dialogs(xlDialogOpen).Show

to select the file I need

Many thanks
 
Michael,

Try this alternative

Dim sFile
sFile = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If sFile <> False Then
Workbooks.OpenText Filename:=sFile, _
Origin:=xlWindows, _
StartRow:=1, _
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(10, 1), _
Array(21, 1), Array(52, 1), _
Array(62, 1), Array(105, 1), _
Array(117, 1), Array(135, 1),
Array(157, 1))
End If

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top