File Location

G

Greg

Word VBA Help gives the following example for the EOF function.

Sub Test()
Dim InputData
Open "MYFILE" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Check for end of file.
Line Input #1, InputData ' Read line of data.
Debug.Print InputData ' Print to the Immediate window.
Loop
Close #1 ' Close file.
End Sub

When I try to run this test, I get an error file not found. How do I
indentify the location of "MYFILE" in the code above? Thanks.
 
J

Jonathan West

Hi Greg,

what is happening here is that the code is looking for a file named "MYFILE"
in the current folder, wherever that happens to be

The current folder is returned by the CurDir function.

Better would be to include the full filepath in the filename when using the
Open command. That avoids any possibility of confusion

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
G

Greg

Thanks Jonathan. With people like you around to help with the help
files even a visually challenged squirrel can find a nut.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top