Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

macro output

ResolvedVersion 2003

Ann has attended:
Excel VBA Intro Intermediate course
Excel VBA Intro Intermediate course

Macro output

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

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

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Hide columns in an Excel 2010 Worksheet

If you don’t want part of the Excel worksheet to be visible or when you don’t want certain data to appear in print outs, then a simple solution is to temporarily hide a column or multiple columns.

Hiding a single column:

1)Right click on the column header of the column you want to hide (this is the grey bar along the top edge of the worksheet)
2)Choose Hide from the menu
3)This column will now be hidden from view

Hide more than one column:

1)In the column header drag select to highlight the columns you want hidden
2)Right click and choose Hide from the menu

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.