Forum

Macro for File save...
 
Notifications
Clear all

Macro for File save base on today

6 Posts
2 Users
0 Reactions
98 Views
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

I tried follow vb script, but not work, can some one hlep to rectify

Sub File_Save()
ActiveSheet.Name = Format(Now, "dd-mmm-yyyy")
 Range("A1").Select
ActiveWorkbook.SaveAs Filename:="D:AGE00OH2104AMC" & ActiveSheet.Name & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
   ReadOnlyRecommended:=False, CreateBackup:=False
   Application.DisplayAlerts = Flase
   ActiveWorkbook.Close
     Range("A1").Select
End Sub

 
Posted : 22/08/2019 3:17 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

The macro work on a seprate Excel file but not in a macro workbook, which  contains some other Macros

 
Posted : 22/08/2019 3:37 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi David,

How exactly does it not work?  If you are getting an error you need to tell us what it is.

When I try this code it works fine, with some minor modifications, like removing the Select statements. 

I do have to change the save path from D:AGE00OH2104AMC to something that exists on my PC.  Does that folder/path exist on your PC?

Sub File_Save()

   ActiveSheet.Name = Format(Now, "dd-mmm-yyyy")

   ActiveWorkbook.SaveAs Filename:="D:AGE00OH2104AMC" & ActiveSheet.Name & ".xls", FileFormat:=xlNormal

   ActiveWorkbook.Close

End Sub

Are you sure you want a .xls file? Because your saving a macro in the workbook.  I'm using Excel 2013, not sure what version you have.  Check the file formats

https://docs.microsoft.com/en-us/office/vba/api/excel.xlfileformat

Regards

Phil

 
Posted : 22/08/2019 3:47 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi David,

I've just seen your 2nd post.  Perhaps the issue is that the other workbook is a .xlsm file?

Again, without the exact error message it's difficult to give advice.

Phil

 
Posted : 22/08/2019 3:49 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Thanks so much Philip!

Yes , agreed it works with a separate file but not work in a Macro workbook.

I capture the screen for reference but sorry they are in Chinese, basically it tells the property of the syntex is not well defined or something like the

parameter is not correctly set 

 
Posted : 22/08/2019 4:04 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Philip, thanks again your effort

Then, how to write the Macro to auto save the file in xlsx  OR  xlsm format,

and at the same time the Work book structure and the Macro is protected.

 
Posted : 22/08/2019 4:31 am
Share: