Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Using Seek In a Macro.

Using Seek In a Macro

Written by Allen Wyatt (last updated October 26, 2019)
This tip applies to Word 97, 2000, 2002, and 2003


Several other tips in other issues of WordTips discuss opening, reading, writing, appending, and closing text files. Another macro command associated with sequential text files is the Seek command. If used on an open file, it positions the internal file pointer at a specific character number in the file. The following code fragment is an example of how it is used:

Open "DOSTEXT.DAT" for Input as #1
iFileLen = LOF(1)
Seek 1, iFileLen / 2

These program lines use the LOF function to determine the length of the file. The last line then positions the internal file pointer half way through the file. All subsequent reading or writing of the file will take place from that position.

You can also use Seek as a function to determine your current position within a text file. This is what this code does:

iCurPos = Seek(1)

This command leaves the internal file pointer where it was but sets iCurPos to a value representing how many characters into the file the pointer is. The iCurPos value is the position at which all subsequent reading and writing of the file will take place.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1385) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Using Seek In a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing the Height of Worksheet Tabs

Do you need your worksheet tabs to be taller than what they are? You can't make the adjustment in Excel, but you can make ...

Discover More

Generating Random Strings

Do you need to generate strings of random characters? The ideas presented in this tip will help you do it in a hurry.

Discover More

Pulling First Letters from Parenthetical Text

When working with text in Excel, you can slice and dice it in many ways. This tip shows how to pull first letters from ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (menu)

Opening Only a Merge Document

After merging the information from a data source into a document, you may decide that you only want to open the merge ...

Discover More

Document Shows as 'In Use' by Another User

Word tries to constantly track who is using various documents, in order to prevent two users from clashing in their edits ...

Discover More

Inserting Only Part of a File

You can easily insert one document within another document. What you may not know is that you can limit which part of a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four minus 0?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.