Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Saving Information in a Non-Document Text File.
Written by Allen Wyatt (last updated March 20, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365
There may be times when you want a macro to save information to a text file. This is very easy to do. All you need is to open the file for output, and then start sending information to the file. The following code fragment writes a text file using this method.
Open "MyFile.Dat" For Output As #1 Print #1, NumValues For J = 1 to NumValues Print #1, UserVals(J) Next J Close #1
In this example, the first thing written to the file is a numeric value indicating how many individual values will follow it. Then a For ... Next loop is used to create the balance of the file. You don't have to use this method of putting data in the file (number of values followed by individual values), but doing so makes it easy to read the information back from the file at a later time.
Why would you want to store information in a non-document text file? They are most often used to store information that may be subsequently needed by your macros (such as configuration information of whatever type you determine necessary) or to save information that may be required by programs other than Word.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (9660) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Saving Information in a Non-Document Text File.
Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!
Word can be configured to save your work periodically; on any time schedule you desire. This tip explains this feature ...
Discover MoreWord has the capability to save your work, in the background, while you continue to edit your documents. This tip ...
Discover MoreWhen switching from one version of Word to another it can be confusing to figure out where all the commands and features ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, 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 Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments