View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Don M. Don M. is offline
external usenet poster
 
Posts: 51
Default I want Excel to determine the correct directory.

Thank you Nate. A combination of your code and Gary's code got my wheels
turning and I was able to do exactly what I needed.

In the end I realized I also had to verify whether or not the date values
were single or double digits. If they were signle I had to add a Zero to the
value so the filenames and paths would work. I also had to know what day of
the week it was today so that I could accurately determine what the Friday
and Saturday values would be.

Here's what I ended up with:

Dim MyDate, MyMonth, MyDay, MyYear, Zero, MyWeekday
Zero = 0

' Year
MyYear = Year(Now()) ' Number of this year
yy = Right(MyYear, 2)

' Month
MyMonth = Month(Now()) ' Number of this month
mm = MyMonth
If mm < 10 Then mm = Zero & mm

' What day of the week is it today?
MyWeekday = Weekday(Now(), 1)
If MyWeekday = 2 Then GoTo Line1001: ' Today is Monday
If MyWeekday = 3 Then GoTo Line1002: ' Today is Tuesday
If MyWeekday = 4 Then GoTo Line1003: ' Today is Wednesday
If MyWeekday = 5 Then GoTo Line1004: ' Today is Thursday
If MyWeekday = 6 Then GoTo Line1005: ' Today is Friday

' Monday
Line1001:
MyDay = Day(Now()) ' Number of this day
fri = MyDay + 4
sat = MyDay + 5
If sat < 10 Then sat = Zero & sat
If fri < 10 Then fri = Zero & fri
GoTo Line1006:

' Tuesday
Line1002:
MyDay = Day(Now()) ' Number of this day
fri = MyDay + 3
sat = MyDay + 4
If sat < 10 Then sat = Zero & sat
If fri < 10 Then fri = Zero & fri
GoTo Line1006:

' Wednesday
Line1003:
MyDay = Day(Now()) ' Number of this day
fri = MyDay + 2
sat = MyDay + 3
If sat < 10 Then sat = Zero & sat
If fri < 10 Then fri = Zero & fri
GoTo Line1006:

' Thursday
Line1004:
MyDay = Day(Now()) ' Number of this day
fri = MyDay + 1
sat = MyDay + 2
If sat < 10 Then sat = Zero & sat
If fri < 10 Then fri = Zero & fri
GoTo Line1006:

' Friday
Line1005:
MyDay = Day(Now()) ' Number of this day
fri = MyDay
sat = MyDay + 1
If fri < 10 Then fri = Zero & fri
If sat < 10 Then sat = Zero & sat

Line1006:


" wrote:

I've had to deal with the same issue with dates whithin a sheet since
I work for an international company. Europeans like the YYMMDD format
and Americans like the MMDDYY format.

I don't want to try and understand your code but I'll give a few hinds
for how I handled it:

try something along these lines:

sub formatDate(strDateFormat as string, strFileDirectory as string)

dim mm, dd, yy as integer
dim strFileName as string

strFileName = dir(strFileDirectory) 'separate file name from directory
if dateFormat = "YYMMDD" then
yy = left(strFileName, 2)
mm = right(left(strFileName, 4),2)
dd = right(left(strFileName, 6),2)

else
mm = left(strFileName, 2)
dd = right(left(strFileName, 4),2)
yy = right(left(strFileName, 6),2)

end if

'then do something with the separate variables,
'likely concatenate (with &) each variable in the appropriate format.

end sub

That's a quick and dirty, but I hope it'll help.
Cheers!
Nate