Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
automatically generate unique serial numbers for invoices | Excel Worksheet Functions | |||
Macro to generate a file from another | Excel Worksheet Functions | |||
Automatically generate a unique file name via macro... | Excel Programming | |||
Automatically generate a unique file name via macro... | Excel Programming | |||
Automatically Generate a unique file name... | Excel Programming |