View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
RobN[_2_] RobN[_2_] is offline
external usenet poster
 
Posts: 230
Default Import File With Specifications

Dave,

How do I modify/add to this code so that once the text file has been opened
I can go back and forth to it not knowing the name of the file until after
it's been selected?

ie I think I need to declare a different variable for the name of the file I
just opened. The "myFileName" refers to the full path and I think I just
want the name of the file.

eg in my code I have
Windows("SupporterStats.txt").Activate
But I want to use the code, below, to open any text file and then run some
more code, before acting again on the unknown name text file.

Rob

"Dave Peterson" wrote in message
...
Saved from a previous post:

Start a new workbook

Start recording a macro that will be stored in this macro workbook.

File|Open your text file that needs to be imported. Format it the way you
like. Insert columns, add headers, freeze panes, widen columns, add
filters, do
the page setup--everything you can think of.

When you're done, save that workbook with the macro.

I like to put a big button from the Forms toolbar on the only worksheet in
that
macro workbook and assign this macro to that big button. I'll add a few
instructions to that sheet, too.

If the file name to open is always the same and in the same location, then
I'm
about done. If the location or file name changes, I'll tweak the code to
ask
for the file.

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

Ripper wrote:

How do I import a file to Excel with a set of specifications? I don't
want
to have to set the fixed length every time I want to import the file.
--
Thanks As Always
Rip


--

Dave Peterson