Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple "Until EOF" procedure??

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
In VBA for Word, I have NOT been able to find a simple code procedure for performing an action (such as Find) until the "End of File" or "End of Document" is reached. I want to be able to have this act on any kind of a document.

What I want is something like:

Do While Not EOF
some actions
Loop

I need this for Word VBA, but could also use it for Excel as well. Any suggestions would be appreciated...thanks!
 
As far as I know EOF(filenumber) is only applicable to sequential file handling.

In the case of using find what I'd do is this:

Code:
set cus_obj = expression.find what:= ...
do until cus_obj is nothing
 'action to be completed on object ...
  set cus_obj = expression.findnext ...
  loop
 
Hello Sagain2k,

The Interaction collection contains and EOF function.
Here's an excerpt from the help file:

EOF Function
-------------
Returns an Integer containing the Boolean value True when the end of a file opened for Random or sequential Input has been reached.

Syntax

EOF(filenumber)

The required filenumber argument is an Integer containing any valid file number.

Remarks

Use EOF to avoid the error generated by attempting to get input past the end of a file.

The EOF function returns False until the end of the file has been reached. With files opened for Random or Binary access, EOF returns False until the last executed Get statement is unable to read an entire record.

With files opened for Binary access, an attempt to read through the file using the Input function until EOF returns True generates an error. Use the LOF and Loc functions instead of EOF when reading binary files with Input, or use Get when using the EOF function. With files opened for Output, EOF always returns True. Hope this helps,
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top