Workbooks.OpenText

  • Thread starter Thread starter Alistair Eberst
  • Start date Start date
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
 
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
 
Dim sPath as String
sPath = ThisWorkbook.Path
if Right(sPath,1) <> "\" then _
sPath = sPath & "\"
Workbooks.OpenText Filename:=sPath & "output1.txt"
 

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

Back
Top