View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Importing text-files

I like to create a dedicated macro workbook that contains the code. And then I
put a big button from the Forms toolbar on the only worksheet in that workbook.
I'll add a few instructions to that sheet, too.

I'd tweak the code to get the name of the file to open from the user and then
include code that adds some more stuff--like formatting, filters, subtotals,
page setup (headers/footers/rows to repeat at top/etc).

Then it actually becomes a tool that makes life a lot easier.

My tweaked code could look a little like:

Option Explicit
Sub Testme01()

Dim myFileName As Variant

myFileName = Application.GetOpenFilename(filefilter:="Text Files, *.TXT", _
Title:="Pick a File")

If myFileName = False Then
MsgBox "Ok, try later" 'user hit cancel
Exit Sub
End If

Workbooks.OpenText Filename:=myFileName '....rest of recorded code here!

End Sub

GARY wrote:

When I open a text-file, the Text Import Wizard is displayed which has
three steps:

In Step 1, I indicate whether the file is delimited or fixed width.
In Step 2, I indicate where I want the column breaks to occur.
In Step 3, I indicate the format of the data in each column.

I very frequently open text-files whose rows have a length of 1,274
characters and, when the column breaks are created, there are 108
columns.

Rather than going through all that work everytime, how can I set up a
"template" (?) that will automatically import the file, break the data
into the 108 columns and format the cells correctly?


--

Dave Peterson