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!

Local Text File Reading in Excel

Status
Not open for further replies.

dac5039

Programmer
Aug 12, 2009
22
US
A text file is created in the same directory as my .mxls file, which I want to be automatically read-in upon opening. How do I specify the location of the file without using an absolute path (I want to be able to send a folder with the excel file and the text file to another machine)?

Thanks,

Dave
 
Hi Dave,

This sounds like a vba question, which you should post in the vba forum.

However, to answer your question, you could specify the text file's path as the workbook's path (which you can always retrieve).


Cheers
[MS MVP - Word]
 
macropod, thank you for your input. I will move this post on to the VBA forum.

In response to your answer, I'm confused by what you mean exactly, so I want to explain my problem a bit better. What my VBA script does is get external text data and store it in the first few columns. Then this data is used to create several graphs which are exported as .png images.

The problem is that I need to be able to pass my Perl, Fortran, and VBA scripts to another machine within a folder, have the Perl and Fortran code create the text file within that folder, and then have the .mxls file retrieve the text file and produce the graphs. So knowing the exact location of the text file won't be possible for other machines. So I tried simply using the VBA code for getting external text data with just the text file's location as the path name, hoping that VBA would look in its working directory by default. This apparently is not the case.

Thanks again for the input,

Dave
 
Hi Dave,

Use something like:
Code:
Dim strFilePath as String, strFileName as String, strFullName as String
strFilePath = ThisWorkbook.Path
strFileName = "MyFile.txt"
strFullName = strFilePath & "\" & strFileName


Cheers
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top