problem with relative paths?

bdee1

Board Regular
Joined
Feb 17, 2003
Messages
105
I have an excel 2007 file (xlsm), which looks for a file in the same directory and if it exists, it opens it and does soem stuff with it. if it doesn't exist, it displays a msgBox saying that it doesn't exist.

It has been working great all week. Today i went to run it and even though the file i am referencing is right there in the same directory, it is saying that it doesn't exist.

It seems liek right before this started happening, I got a message about macros not being allowed which was weird because its been allowing them all week. not sure if thats related or not but i went in and changed the macro security to allow it.

so here is the code i am using to check for the existence of the file:

MyFileName = "Daily Flash Sheet_Glen Eddy.xlsx"
If Dir(MyFileName, 0) = MyFileName Then
do some stuff
Else
MsgBox "File does not exist"
End If
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I just checked the file properties and it doesn't seem to be read only. I also modified the code to be like you suggested and it still doesn't see the file.
 
Upvote 0
I cant figure what changed between yesterday and today that made it stop working. the file is definitely there so i don't know why the Dir function isn't seeing it.


whats weird is that if i run it on another computer it seems to work. so is there a setting in excel that would cause it to do this on my computer?
 
Upvote 0
I found that for some reason I have to enter the full path in order to get the Dir function to work. Before I just had the filename and it worked - weird that it needs the full path now.
 
Upvote 0
I think that if you are not in the same folder as the file then Dir requires the full path.
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,135
Members
452,890
Latest member
Nikhil Ramesh

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