Workbooks.OpenText

A

Alistair Eberst

I'd like to use Workbooks.OpenText to open a text file in the same folder
as the xl file I'm running it from.

At the moment an absolute reference works "C:\...\...\output1.txt.", but the
file name on its own doesn't.

Workbooks.OpenText FileName:= "output1.txt"

Any suggestions ?

Thanks
 
A

Alan Howells

Excel is trying to open the file in the current directory (call CurDir to
get the current directory).

If this is the wrong directory then change it using ChDir and ChDrive.

Alan
 
T

Tom Ogilvy

Dim sPath as String
sPath = ThisWorkbook.Path
if Right(sPath,1) <> "\" then _
sPath = sPath & "\"
Workbooks.OpenText Filename:=sPath & "output1.txt"
 
Top