Forum Discussion
Excel Help
- Nov 12, 2023
You can achieve this with a VBA (Visual Basic for Applications) macro in Excel. The following code saves each sheet as an individual workbook in a defined location with the sheet name and the current date appended to the filename. In the example, you will find an approach.
This macro will run when the workbook is closed:
Open the Visual Basic for Applications editor by pressing Alt + F11, and then insert this code in the workbook's module.
Vba code (is untested):
Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim ws As Worksheet Dim savePath As String Dim wb As Workbook Dim fileName As String Dim currentDate As String ' Define the folder path where you want to save the separated workbooks savePath = "C:\Your\Folder\Path\" ' Update with your desired path ' Create the folder if it doesn't exist If Dir(savePath, vbDirectory) = "" Then MkDir savePath End If For Each ws In ThisWorkbook.Worksheets ' Create a new workbook for each worksheet Set wb = Workbooks.Add ws.Copy Before:=wb.Sheets(1) ' Get the current date to append to the filename currentDate = Format(Now(), "yyyy-mm-dd") ' Form the filename with sheet name and date fileName = savePath & ws.Name & "_" & currentDate & ".xlsx" ' Save the new workbook with the formatted name and close it wb.SaveAs fileName wb.Close SaveChanges:=False Next ws End SubThis code will trigger when the workbook is closed. It loops through each sheet, creates a new workbook, copies the sheet into that new workbook, and saves it in the defined location with the sheet name and the current date.
Remember to change savePath = "C:\Your\Folder\Path\" to the path where you want to save the separate workbooks. This script will create a new file for each sheet upon closing the workbook.
AI was used to support the text.
VBA functionality is not available or possible in all Excel versions. It may also depend on where it is stored. However, some information was requested that you did not provide, so my help is unfortunately limited due to a lack of information.
But still hope it helped you
.My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.
There are many unanswered questions regarding your concerns.
What exactly do you want to accomplish?
If you want the whole thing finished, I recommend commissioning it.
Here you can get help with parts of your project, such as a formula... but not complete the entire workbook.
Questions about master sheet, what is meant when the master sheet is closed?
Is it workbooks or worksheets?
However, it is desirable if you include more detailed information, information about the problem, about your Excel version, operating system, storage medium, etc.
Thank you for your understanding and patience.