#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Re-use Excel macro

Hello:
Do know how I can re-use an Excel macro. For example, I have imported a tab
delimited ASCII file into Excel and recorded the process in a macro. Is it
possible to use that macro to import other tab delimited ASCII files(so open
the macro and open another file using the macro without having to go through
the wizard - the wizard is automatically opened because of the tab delimiters
so that the user can choose the kind of delimiter and set the data format
type, if necessary, for the columns)
Thanks
Jade
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Re-use Excel macro

Yep.

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.

Then I can distribute this macro workbook to other users (and use it myself) so
that I can just click the giant button to invoke the macro that imports the text
file.

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

Jade5 wrote:

Hello:
Do know how I can re-use an Excel macro. For example, I have imported a tab
delimited ASCII file into Excel and recorded the process in a macro. Is it
possible to use that macro to import other tab delimited ASCII files(so open
the macro and open another file using the macro without having to go through
the wizard - the wizard is automatically opened because of the tab delimiters
so that the user can choose the kind of delimiter and set the data format
type, if necessary, for the columns)
Thanks
Jade


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel application.quit in macro problem TimkenSteve New Users to Excel 3 August 17th 06 06:36 PM
How to stop Excel remembering/loading macro from previously opened Workbook Norman Yuan Excel Discussion (Misc queries) 4 June 17th 06 04:13 PM
Macro Help In Excel welshlad Excel Discussion (Misc queries) 14 October 26th 05 02:34 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
passing arguments from an excel macro to a word macro KWE39 Excel Discussion (Misc queries) 1 July 7th 05 03:56 PM


All times are GMT +1. The time now is 09:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"