View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Koppel Greg Koppel is offline
external usenet poster
 
Posts: 79
Default Check if a directory exists and if it doesn t...

Use the Dir() function. It returns "" if the file doesn't exist, so
something like

myFile = Dir(pathname...)
If myFile = "" then

HTH, Greg

"Grek " wrote in message
...
Hi,

To open a file in a directory (C:\Export Archive\yyyymmdd\) with date
day-1 I use the follwing code :

variablefile = Range("E1").Value

Workbooks.Open Filename:= _
"C:\Export Archive\" & Format(Now() - 1, "yyyymmdd") & "\" &
"Export" & variablefile & ".xls"

(a directory is saved every day from monday to friday)

My code works pretty good, exept on monday because it looks for the
directory day-1. And as there is no directory saved with sunday's or
saturday's date, it doesn t work. Same problem with holidays.

So, I would like to improve my code to do something like "open the
directory with date day-1. If the directory does not exist, try day-2,
or day-3,... until it finds the directory with the most recent date.

Could you help me to do that please ?

Maybe something like setting the date as variable and increasing it by
doing a loop until it finds a directory with the same date ?

Thank you very much in advance for you help,

Greg


---
Message posted from http://www.ExcelForum.com/