macro output
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Macro output

Macro output

resolvedResolved · Low Priority · Version 2003

replyReply Mon 29 Jun 2009, 16:55Delegate Ann said...

Macro output

I want to create a macro that creates a text file based on the information in the excel file.

For upcoming training course dates see: Pricing & availability

replyReply Tue 30 Jun 2009, 11:13Delegate Tony said...

RE: Macro output

Ann, please see the code below.

This was created by the macro recorder while I simply saved my Excel workbook as type txt ( tab delimited ) , by choosing .txt rather than the default .xls in the drop-down box on the Save As dialog.

This macro saves the active workbook to a particular location ( C:\Documents and Settings\txmoore\Desktop) and with a particular filename ( MyTextFile.txt ), both of which are hard-coded.

If you need your macro to always save the active workbook to the same place, with the same name, then simply replace my details with your own.

For a full list of the options available, search excel vba help for " SaveAs Method"

If however, the workbook to be saved, the location, or filename need to vary, then define these as variables instead, and use the variable names within the saveas arguments.

If this is the case, then lalso ook within help at the GetSaveAsFileName method, which can be called within your code to display the Save as dialog box, and allow you to browse to your desired location, and choose your filename and type.

The GetSaveAsFileName method does not actually save anything, but simply obtains the filename / location details that you have chosen which can then assigned to variables that are then used by a seperate SaveAs method to actually save the file.

Regards,

Tony Moore

Sub SaveAsTextFile()
'
' SaveAsTextFile Macro
' Macro recorded 30/06/2009 by Tony Moore x8246
'

'
' ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\txmoore\Desktop\MyTextFile.txt", _
FileFormat:=xlText, CreateBackup:=False
End Sub

 

Please browse our web site to find out more about
introduction excel training and other Microsoft training courses.

Excel tip:

Autonumber in Excel

To create an autonumber field, can use the Offset() function.

In cell A1, enter the number 1.
Then in cell A2, enter this formula:

=OFFSET(A2,-1,0)+1

Then copy the formula from cell A2, down as far as you need.

See also: Autonumber in Excel forum post.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard