ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Automatic File Names (https://www.excelbanter.com/excel-discussion-misc-queries/107471-automatic-file-names.html)

chrismusic79

Automatic File Names
 
I am trying to create a backup file using an autoexec macro, but am
unable to find the command to put in the macro to create the file name.

I need to have the file name auto-incremental depending on what name is
in the folder.

Could anyone also tell me how to create the file name as the current
date..

Thanks.


Allllen

Automatic File Names
 
Hello Chris,

How about this. It doesn't go and look in the folder for what is already
there, but it saves your active workbook as for example "BACKUP 080629.xls"
inside the folder you specify.

If you really want to get it to look in the folder to see what is there,
then add one, post the question under excel programming.

ActiveWorkbook.SaveAs Filename:="\\SERVER\FOLDER\"BACKUP" & Format(Year(Now)
- 2000, "00") & Format(Month(Now), "00") & Format(Day(Now), "00") & ".xls"


HTH
---
Allllen


"chrismusic79" wrote:

I am trying to create a backup file using an autoexec macro, but am
unable to find the command to put in the macro to create the file name.

I need to have the file name auto-incremental depending on what name is
in the folder.

Could anyone also tell me how to create the file name as the current
date..

Thanks.



Dave Peterson

Automatic File Names
 
I think I'd use the time and date. It makes your code easier and even allows
you to know when the save took place based on the filename itself.

dim myFileName as string
with activeworkbook
myfilename = left(.fullname,len(.fullname)-4) & _
"_" & format(now,"yyyymmdd_hhmmss") & ".xls"

.savecopyas myfilename
end with




chrismusic79 wrote:

I am trying to create a backup file using an autoexec macro, but am
unable to find the command to put in the macro to create the file name.

I need to have the file name auto-incremental depending on what name is
in the folder.

Could anyone also tell me how to create the file name as the current
date..

Thanks.


--

Dave Peterson


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com