SaveAS w/ a variable name problem

J

Jeffp

Hi
this one has me confused but seeing that I'm a newbie it's probably something dumb
There is other code involved here but this is the problem. If I use the #30 this works fine(saves the file as 30comp report.xls) but if I use #31 it saves the file as 1compreport.xls.
It also won't work (not that I need it too) for any number over 30, it seems in testing
Can you help me understand
Thanks to anyone that tries (I"m a little thick
jef

fname = Day(Now() + (31 - Day(Now()))
ActiveWorkbook.SaveAs Filename:=
"C:\My Documents2004\" & fname & "CompReport.xls", CreateBackup:=Fals
 
P

Patrick Molloy

first off, fname will always be 31 in your formula
if today = May 1st
Day(Now() + (31 - Day(Now())))
day( (1/5 + ( 31 - day(1/5))) => day(1/5 + (31-1) )
=> day( 1/5+ 30) => 31

We always use ISO dates , which are th eformat YYYYMMDD
- big advantage - date is not ambiguous and will always
sort correctly.

add
debug.print fname
to see what value has been assigned to the variable.

What has fname been declared as?
if string then try

fname =format$( Day(Now() + (31 - Day(Now()))) , "00")

your code should work unless fname returns an
unacceptable piece of text - that is text which one
cannot use as a filename


Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
Hi,
this one has me confused but seeing that I'm a newbie it's probably something dumb.
There is other code involved here but this is the
problem. If I use the #30 this works fine(saves the file
as 30comp report.xls) but if I use #31 it saves the file
as 1compreport.xls.
It also won't work (not that I need it too) for any
number over 30, it seems in testing.
 
J

jeffp

Patrick
Actually , I didn't do a very good job describing this because I tried to simplify it for thispost. I'm actually using a variable where '31' is . But it shows my question just the same, that "fname" picks up "30" but not "31" or any number over 30
Dim fname as byte (but I tried others
jef

----- Patrick Molloy wrote: ----

first off, fname will always be 31 in your formul
if today = May 1s
Day(Now() + (31 - Day(Now()))
day( (1/5 + ( 31 - day(1/5))) => day(1/5 + (31-1)
=> day( 1/5+ 30) => 3

We always use ISO dates , which are th eformat YYYYMMD
- big advantage - date is not ambiguous and will always
sort correctly

add
debug.print fnam
to see what value has been assigned to the variable

What has fname been declared as
if string then tr

fname =format$( Day(Now() + (31 - Day(Now()))) , "00"

your code should work unless fname returns an
unacceptable piece of text - that is text which one
cannot use as a filenam


Patrick Mollo
Microsoft Excel MV

-----Original Message----
Hi
this one has me confused but seeing that I'm a newbie it's probably something dumb
There is other code involved here but this is the
problem. If I use the #30 this works fine(saves the file
as 30comp report.xls) but if I use #31 it saves the file
as 1compreport.xls.
It also won't work (not that I need it too) for any
number over 30, it seems in testing
 
Top