Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to write a macro to save a worksheet with a
unique file name, preferably using a cell value, every time the macro is used. Can anyone help me? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Why would a cell value be unique whenever you run the code ? Anyway, here's one that uses a cell and also date/time. Unique unless you run it twice in the same second: Function UniqName() As String UniqName = Sheets(2).Range("B3").Value & _ Format(Now, "yymmddhhmmss") & ".xls" End Function Sub test() MsgBox "Save me as " & UniqName End Sub -- HTH. Best wishes Harald Followup to newsgroup only please. "Noell" wrote in message ... I am trying to write a macro to save a worksheet with a unique file name, preferably using a cell value, every time the macro is used. Can anyone help me? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Activeworkbook.saveas cells(1, 1)
whatever is cell A1 will now be the filename. You can enter that into the workbook_beforeclose event and that way before the workbook is closed it will save it as the new name. "Noell" wrote in message ... I am trying to write a macro to save a worksheet with a unique file name, preferably using a cell value, every time the macro is used. Can anyone help me? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Noell
You can use the date and time as a part of the filename Sub Test() Dim wb As Workbook Dim strdate As String strdate = Format(Now, "dd-mm-yy h-mm-ss") Set wb = ActiveWorkbook With wb .SaveAs Sheets("Sheet1").Range("A1").Value _ & " " & strdate & ".xls" 'wb.Close False End With End Sub -- Regards Ron de Bruin (Win XP Pro SP-1 XL2002 SP-2) www.rondebruin.nl "Noell" wrote in message ... I am trying to write a macro to save a worksheet with a unique file name, preferably using a cell value, every time the macro is used. Can anyone help me? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
2007 Macro to Open File, Delete Contents, Save New File | Excel Discussion (Misc queries) | |||
Auto save file copy with unique filename | Excel Worksheet Functions | |||
macro save a file name from a cell in 1st worksheet | Excel Discussion (Misc queries) | |||
Macro Save File (Unique file name) | Excel Worksheet Functions | |||
Automate open file, update links, run macro, close and save file | Excel Programming |