File Locations (From a Macro) "File Not Found"

cool_capybara

New Member
Joined
Apr 8, 2004
Messages
16
Sadly, I've got one of those problems that are intermitant...

I have an excel file and a .txt file that sit in the same folder together. The excel file has a macro that reads (or writes) a piece of data to that file (simply):

Code:
Sub Macro2()
Dim Cntr, NewInvoiceNumber As Integer
Cntr = FreeFile()

Open "incident.txt" For Input As #Cntr
Input #Cntr, NewInvoiceNumber
Close #Cntr

This works almost all the time. However, when I e-mail the folder to a colleague, and they have the same folder structure (both files in the same folder), they will get a "File Not Found" error.

As weird as it sounds, sometimes when I show off the version on my own PC, it will work 9 times out of 10...but when it really counts, I'll get the "File Not Found" error too.

Is there any way to explicitly state that the file is in the same folder? My guess is that I have it right (w/ no stated path, it assumes the same location)...or any other suggestions?

Thanks!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Could you not actually add the path?

Without it Excel will probably be looking in whatever the current directory is.
 
Upvote 0
Thanks for your reply.

The problem is that I can't force the users to put the folder in a particular spot, so I figured if I can get it always look for the file in the same folder regardless of that folder's path, that would be ideal.

My programmin experience tells me that this should work...unfortunately, Excel is of a different opinion.

Is it possible to explicitly state some sort of path to the same folder that the excel file is in (dynamically)?
 
Upvote 0
Well you could use ThisWorkbook.Path.
Code:
Open ThisWorkbook.Path & "\incident.txt" For Input As #Cntr
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top