Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Appending to a Non-Excel Text File.
Written by Allen Wyatt (last updated December 5, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
When using a macro to write information to a text file, you may want to add information to an existing file, rather than creating a new text file from scratch. To do this, all you need to do is open the file for Append rather than Output. The following code shows this process:
Open "MyFile.Dat" For Append As #1 For J = 1 to NewValues Print #1, UserVals(OrigVals + J) Next J Close #1
When the file is opened for Append mode, any new information is added to the end of the file, without disturbing the existing contents.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9206) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Excel here: Appending to a Non-Excel Text File.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Sometimes, when importing data created by other programs, you may find that there is too much for Excel to handle. Here's ...
Discover MoreExcel keeps track of the most recent workbooks you've used. If you want to access that information in a macro, you'll ...
Discover MoreIf you get errors in Excel that your filenames are too long, it can be confusing and frustrating. Applying the ideas ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments