ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro help (https://www.excelbanter.com/excel-discussion-misc-queries/226729-macro-help.html)

rita

Macro help
 
I am somewhat familiar with macros and understand how to record one. I am
using Excel 2007. I am trying to create a macro: (file, save as, "file
name", and then have Excel finish with the "save" function), but I keep
getting the following error message. Please help! Thanks.

"the following features cannot be saved in macro-free workbooks: VB
project. To save a file with these features, click no and then choose a
macro enabled file type in the file list. To continue saving as a macro-free
workbook click yes."

I have already chosen "enable all macros" in the trust center.


rita

Macro help
 
I figured it out! Now I need to know how to name the file a different name
than the original and save it as a new one. Does anyone know the code for
this? Thanks.

"Rita" wrote:

I am somewhat familiar with macros and understand how to record one. I am
using Excel 2007. I am trying to create a macro: (file, save as, "file
name", and then have Excel finish with the "save" function), but I keep
getting the following error message. Please help! Thanks.

"the following features cannot be saved in macro-free workbooks: VB
project. To save a file with these features, click no and then choose a
macro enabled file type in the file list. To continue saving as a macro-free
workbook click yes."

I have already chosen "enable all macros" in the trust center.


JLatham

Macro help
 
I think you're probably already there! The same .SaveAs function also
accepts a new filename:

ActiveWorkbook.SaveAs _
Filename:="C:\Users\JLatham\Documents\NewName.xlsm ", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

And you can substitute a variable for the filename, allowing you to generate
one before executing the command.

Assuming you want to put it into the same folder with the original you can
get the original path from the workbook's .FullName
filePath=Left(ThisWorkbook.FullName, _
InstrRev(ThisWorkbook.FullName,Application.PathSep arator))

and build up some new name:
NewName = "MyNewFileName_" & Year(Now()) & Month(Now()) & Day(Now()) & ".xlsm"
'put the two together
NewName = filePath & NewName

Then execute your .FileSave using NewName for the Filename:= parameter, as:
Filename:=NewName


"Rita" wrote:

I figured it out! Now I need to know how to name the file a different name
than the original and save it as a new one. Does anyone know the code for
this? Thanks.

"Rita" wrote:

I am somewhat familiar with macros and understand how to record one. I am
using Excel 2007. I am trying to create a macro: (file, save as, "file
name", and then have Excel finish with the "save" function), but I keep
getting the following error message. Please help! Thanks.

"the following features cannot be saved in macro-free workbooks: VB
project. To save a file with these features, click no and then choose a
macro enabled file type in the file list. To continue saving as a macro-free
workbook click yes."

I have already chosen "enable all macros" in the trust center.



All times are GMT +1. The time now is 12:39 PM.

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