Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default using macro to save worksheet with unique file name

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default using macro to save worksheet with unique file name

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default using macro to save worksheet with unique file name

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default using macro to save worksheet with unique file name

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
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
2007 Macro to Open File, Delete Contents, Save New File Flintstone[_2_] Excel Discussion (Misc queries) 2 February 1st 10 11:25 PM
Auto save file copy with unique filename Allen Excel Worksheet Functions 1 June 27th 06 08:18 PM
macro save a file name from a cell in 1st worksheet karene Excel Discussion (Misc queries) 2 April 10th 06 12:13 PM
Macro Save File (Unique file name) SJC Excel Worksheet Functions 5 October 27th 05 10:09 PM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


All times are GMT +1. The time now is 05:41 PM.

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

About Us

"It's about Microsoft Excel"