Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Automatically generate a unique file name via macro...

I will take credit for the typo.

---------------
Thisworkbook.SaveAs "X:\SpecialFolder\ & "ABC" & _
format(now,"yyyymmdd_hhmm") & ".xls"

Regards,
Tom Ogilvy
----------------------

The reason I left ABC as separate is because he indicated he had many users
and I thought he might want to identify them separately so ABC would be
replaced by a variable - but doing that probably caused the missing double
quote :-(.

Dim sName as String
sName = "ABC"

Thisworkbook.SaveAs "X:\SpecialFolder\" & sName & _
format(now,"yyyymmdd_hhmm") & ".xls"

--
Regards,
Tom Ogilvy


"Bob Kilmer" wrote in message
...
Ian,
If you get the statement right, it will work correctly from now 'til
doomsday. The following is correct, given what appears. You are missing a

"
in your posted example, and there is no need to concatenate
"X:\SpecialFolder\" and "ABC". (I realize it is just an example of what

you
have been trying to get working.)

Debug.Print "X:\SpecialFolder\ABC" & Format(Now, "yyyymmdd_hhmm") & ".xls"

If any part of your path or file name ever includes embedded spaces, you

may
need additional quotation marks to enclose the string, so you might just
accommodate this from the beginning. For example,

Debug.Print """X:\Path With Spaces\ABC" & Format(Now, "yyyymmdd_hhmm") &
".xls"""

Trim(Date) returns a string like this: 7/17/2003. Notice that without

hours,
minutes, or seconds, Trim(Date) will produce the same string all day long.
If an individual is creating more than one file per day, this will not be
sufficient by itself.

The Trim() function takes a string as an argument and returns the same
string but without spaces that it may have had on its ends. 'Now' returns
the system date and time as a string. 'Date' returns the system date.

'Time'
returns the system time. Except for formatting (i.e.,spaces), Date & Time

=
Now.

Rnd returns a pseudo-random number like 0.7747401 that could be used to
increase the likelihood that filenames are unique. Using Format(Now,
"yyyymmdd_hhmm") produces a new filename every minute and Format(Now,
"yyyymmdd_hhmmss") , every second, so unless you are creating files more
often than that, you don't need Rnd, but you could use it instead or in
addition if you wanted to. The following will return a numeric string

whose
length is always 8 and has a leading decimal (which could be trimmed off).

Format(Rnd(), ".0000000")

HTH,
Bob Kilmer


"Ian L." wrote in message
...
I have an excel (XP version) application in use on a
network. The app is being run by 50+ different users,
and currently they output the final result sheet to a
printer on completion.

I would like to save some trees and instead of printing
the output, I would like to save it to a folder on the
network. The problem is, each user prints between 5 &
10 of these sheets per shift.

Not all of the users are computer savvy, so in order to
avoid everyone saving their files over everyone elses, I
would need to write a macro that would save the file
automatically to a specific folder. At the same time it
would also need to generate a unique file name for each
individual user!

Does anyone know if this is possible, and can you give me
any pointers please?

I tried something like this:

Thisworkbook.SaveAs "X:\SpecialFolder\ & "ABC" & _
format(now,"yyyymmdd_hhmm") & ".xls"

but I get syntax errors or expected end of statement
errors.

Thanks in advance.

Ian.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
automatically generate unique serial numbers for invoices nhlanhla Excel Worksheet Functions 1 October 2nd 08 12:50 PM
Macro to generate a file from another Dileep Chandran Excel Worksheet Functions 10 December 4th 06 02:52 PM
Automatically generate a unique file name via macro... John Green[_2_] Excel Programming 1 July 18th 03 03:06 AM
Automatically generate a unique file name via macro... Randall Arnold[_2_] Excel Programming 1 July 17th 03 08:56 PM
Automatically Generate a unique file name... Ian L Excel Programming 3 July 15th 03 02:08 AM


All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"