#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default file save as

I want to save a file on a macro button so it saves the file as the same name
but gives the saved date. The file will be in the location each time and
will build day on day.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 109
Default file save as

Phil Wales wrote:
I want to save a file on a macro button so it saves the file as the same name
but gives the saved date. The file will be in the location each time and
will build day on day


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default file save as

This may get you started:

Option Explicit
Sub testme()

Dim myFileName As String
Dim myExt As String

myFileName = ThisWorkbook.Name

'find extension
myExt = Mid(myFileName, InStrRev(myFileName, "."))

'strip off extension
myFileName = Left(myFileName, InStrRev(myFileName, ".") - 1)

'Check last x characters for date format
If Right(myFileName, 11) Like "_####-##-##" Then
'strip off previous date
myFileName = Left(myFileName, Len(myFileName) - Len("_####-##-##"))
End If

'add date

myFileName = myFileName & Format(Date, "_yyyy-mm-dd") & myExt

With ThisWorkbook
If myFileName = .Name Then
'same date, just do a save
.Save
MsgBox "Saved using same name"
Else
'don't show overwrite prompt
Application.DisplayAlerts = False
'save as new name
.SaveAs Filename:=.Path & "\" & myFileName, FileFormat:=.FileFormat
Application.DisplayAlerts = True
End If
End With

End Sub

I used a date format of: _yyyy-mm-dd

I find that it's easier for sorting and the underscore makes it easier to read.



Phil Wales wrote:

I want to save a file on a macro button so it saves the file as the same name
but gives the saved date. The file will be in the location each time and
will build day on day.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default file save as

Thanks Dave - that sounds spot on

"Dave Peterson" wrote:

This may get you started:

Option Explicit
Sub testme()

Dim myFileName As String
Dim myExt As String

myFileName = ThisWorkbook.Name

'find extension
myExt = Mid(myFileName, InStrRev(myFileName, "."))

'strip off extension
myFileName = Left(myFileName, InStrRev(myFileName, ".") - 1)

'Check last x characters for date format
If Right(myFileName, 11) Like "_####-##-##" Then
'strip off previous date
myFileName = Left(myFileName, Len(myFileName) - Len("_####-##-##"))
End If

'add date

myFileName = myFileName & Format(Date, "_yyyy-mm-dd") & myExt

With ThisWorkbook
If myFileName = .Name Then
'same date, just do a save
.Save
MsgBox "Saved using same name"
Else
'don't show overwrite prompt
Application.DisplayAlerts = False
'save as new name
.SaveAs Filename:=.Path & "\" & myFileName, FileFormat:=.FileFormat
Application.DisplayAlerts = True
End If
End With

End Sub

I used a date format of: _yyyy-mm-dd

I find that it's easier for sorting and the underscore makes it easier to read.



Phil Wales wrote:

I want to save a file on a macro button so it saves the file as the same name
but gives the saved date. The file will be in the location each time and
will build day on day.


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default file save as

Thanks for the code Dave, I have been able to use it in saving a template in
2007.
However it saves the resultant file as .xlsx not macro enabled .xlsm.


Can you show me the adjusted code?

Murph



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default file save as

I don't use xl2007 to help.

But Ron de Bruin can!
http://www.rondebruin.nl/saveas.htm

Murph wrote:

Thanks for the code Dave, I have been able to use it in saving a template in
2007.
However it saves the resultant file as .xlsx not macro enabled .xlsm.

Can you show me the adjusted code?

Murph


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default file save as

Thanks again Dave.
I couldn't get my head around some of Ron's great code but adapted yours by
storing the macros in Personal macro file and changing your code to Active
rather than This.

Working well so far, fingers crossed!
Murph

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
SAVE and SAVE AS options disappeared from the drop down FILE menu [email protected] Excel Discussion (Misc queries) 2 July 12th 07 09:14 AM
when i save xls file, debug script is running and canno't save fil Imtiaz Excel Discussion (Misc queries) 1 July 16th 05 03:47 PM
'document not saved' for 'save' or 'save as' an EXCEL file Judy Chuang Excel Discussion (Misc queries) 1 July 11th 05 10:12 PM
Excell2003 (SP-1) File > Save and File > Save As.. grayed out Joe Murphy Excel Discussion (Misc queries) 0 March 9th 05 10:00 PM
Save Excel file - prompts to save - no Volitile functions used POWER CERTS Excel Worksheet Functions 2 November 1st 04 09:27 PM


All times are GMT +1. The time now is 08:42 AM.

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"