Thread: macro
View Single Post
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'd do this...

Start a new workbook.
record a macro when you open that file and add all your features
(formatting/sorting/filtering/page setup, etc.)

Then go back to the first worksheet and add a button from the Forms toolbar.

Assign your macro to that button.

Then save that workbook and give it to anyone who wants to import a file with
the same name and same layout.

If the name of the file could change, you could modify your recorded macro to
ask for the name with something like:

Option Explicit
Sub testme()

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

You could even continue recording when you save the imported text file as a
normal workbook (*.xls) and include that in your code.



Pam Coleman wrote:

If I create a macro on my PC to format a text file that is being brought over
to excel on a weekly basis (and it is saved in a file on our server), can the
macro be saved so that every week when someone else opens up a new file, the
macros can run to format that file? Sometimes I notice when you create a
macro in your workbook on your PC, it does not show in other excel
workbooks. Thanks,


--

Dave Peterson