Random file name

  • Thread starter Thread starter Robert Melbo
  • Start date Start date
R

Robert Melbo

Is there a way to create a random/unique workbook name in Excel that
can be created by a macro at the beginning, the macro continues on
with its chores, and then, at the end, deletes that workbook? The
workbook is temporary in nature and does not need to exist after the
macro executes.

I am more familiar with writing code in Foxpro than I am with Excel.


Ahí namá,


Robert Melbo
 
Just use time as a source for the name - it isn't random, but it shouldn't
be duplicated

sName = Format(now,"yyyymmdd_hhmmss") & ".xls"

to demo from the immediate window:
? Format(now,"yyyymmdd_hhmmss") & ".xls"
20030721_095957.xls


But you can create a new workbook and work with it, then

Activeworkbook.Close SaveChanges:=false

without giving it a name or saving it.

Regards,
Tom Ogilvy
 
Robert Melbo said:
Is there a way to create a random/unique workbook name in Excel that
can be created by a macro at the beginning, the macro continues on
with its chores, and then, at the end, deletes that workbook? The
workbook is temporary in nature and does not need to exist after the
macro executes.

Why would you want to do this ?

If you open an Excel session you get a workbook who's name
defaults to Book1 but if you dont save it when you close
the session it never gets written to disk anyway.

If you really want a unique name for the workbook generate
a GUID

http://support.microsoft.com:80/support/kb/articles/q176/7/90.asp&NoWebContent=1&NoWebContent=1

Keith
 
If you really do need to create a temp name, Excel vba has a method that
generates random names. It's advertised for this purpose. You would have
to adjust it to fit your needs. There are many other different options
besides this though.

Sub Demo()
Dim TempFileName
TempFileName = Left$("Excel_" &
CreateObject("Scripting.FileSystemObject").GetTempName, 14)
Debug.Print TempFileName
End Sub

returns: Excel_radBD8CE
 
Back
Top