I have a Workbook with multiple worksheets. Some worksheets contain formulas, some worksheets are protected but imported worksheets are not protected. The active workbook was named "Analyze.xlsm"
I want in the same folder the workbook 'Analyze.xlsm' save as 'Analyze-Month-Year-Date-Time.xlsx' under conditions.
These are the conditions
- When a user click on the 'Save' button on 'Quick Access Toolbar'
or
- When a user click on 'File' -> 'Save' or 'Save As'
or
- When a user click on 'CommandButton2_Click' on 'Helper' sheet
The VBA macros should do the following
1. Pass through all unprotected worksheets and set 'Locked' and 'Hidden' options to all cells in the range 'A1:KA500'
2. Set protection to each worksheet in the active workbook (the password should be defined in the VBA code).
3. The VBA should read the text in 'D1' cell (Month) on 'Helper' sheet.
4. The VBA should read the number 'E1' cell (Year) on 'Helper' sheet.
5. Activate the 'Save As' dialog window and set it up.
- new file name such as "Analyze-Month-Year-Date-Time" in .xlsx format (Date format = yyyy-mm-dd, Time format = hh:mm)
6. If the user clicks on the 'Cancel' button then 'Exit Sub' and returns to the active worksheet. (Is this a good plan, how the user can close the workbook and give up on saving?)
But there is an additional problem,
in 'Excel -> Options -> Trust Center settings' disabled the macros permission option (so must be). The "Disable all macros with notification" radio button has been checked. The folder in which the Workbook is located is "Tusted Locations". Also, I plan to run this VBA macro via CommandButton2_Click.
I've found several VBA macros, but I can not adapt them to my requirements.
First VBA
Second VBA
Is this possible or too complicated?
Can anyone adapt the code to one of the VBA macros or does anyone have a simpler solution?
or perhaps someone has a different advice?
I would appreciate if anyone could help me.
I want in the same folder the workbook 'Analyze.xlsm' save as 'Analyze-Month-Year-Date-Time.xlsx' under conditions.
These are the conditions
- When a user click on the 'Save' button on 'Quick Access Toolbar'
or
- When a user click on 'File' -> 'Save' or 'Save As'
or
- When a user click on 'CommandButton2_Click' on 'Helper' sheet
The VBA macros should do the following
1. Pass through all unprotected worksheets and set 'Locked' and 'Hidden' options to all cells in the range 'A1:KA500'
2. Set protection to each worksheet in the active workbook (the password should be defined in the VBA code).
3. The VBA should read the text in 'D1' cell (Month) on 'Helper' sheet.
4. The VBA should read the number 'E1' cell (Year) on 'Helper' sheet.
5. Activate the 'Save As' dialog window and set it up.
- new file name such as "Analyze-Month-Year-Date-Time" in .xlsx format (Date format = yyyy-mm-dd, Time format = hh:mm)
6. If the user clicks on the 'Cancel' button then 'Exit Sub' and returns to the active worksheet. (Is this a good plan, how the user can close the workbook and give up on saving?)
But there is an additional problem,
in 'Excel -> Options -> Trust Center settings' disabled the macros permission option (so must be). The "Disable all macros with notification" radio button has been checked. The folder in which the Workbook is located is "Tusted Locations". Also, I plan to run this VBA macro via CommandButton2_Click.
I've found several VBA macros, but I can not adapt them to my requirements.
First VBA
Code:
Sub SaveActiveXLSMWbkAsXLSX()
ThisWorkbook.Save 'Optional
Application.DisplayAlerts = False
ThisWorkbook.SaveAs ActiveWorkbook.Path & "\MyFileName - " & Format(Date, "yyyy-mm-dd"), 51 '51 = xlsx
Application.DisplayAlerts = True
'ThisWorkbook.Close 'Optional
End Sub
Code:
Option Explicit
Sub SaveAsName()
Dim save_as As Variant
Dim file_name As String
Dim ProgramName As String
file_name = ProgramName
' Get the file name.
save_as = Application.GetSaveAsFilename(file_name, _
FileFilter:="Excel Files,*.xlsx,All Files,*.*")
' See if the user canceled.
If save_as = False Then Exit Sub
' Save the file with the new name.
Application.DisplayAlerts = False
If LCase$(Right$(save_as, 4)) <> ".xlsx" Then
file_name = save_as & ".xlsx"
End If
ActiveWorkbook.SaveAs Filename:=save_as, FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
End Sub
Can anyone adapt the code to one of the VBA macros or does anyone have a simpler solution?
or perhaps someone has a different advice?
I would appreciate if anyone could help me.