Forum Discussion

Rahuloo7's avatar
Rahuloo7
Copper Contributor
Nov 25, 2023

Excel Automate File Name with date and time

Hey Guys,

I'm Not an Expert or Coder but want to ask help from You guys , I want whenever I Press Clr+S it will save my file with name with and time .

Is it Possible or not.

 

It's a request bro any body can help me over it let me know please.

 

  • Yes, it's possible to create a script or a macro that will save your file with a specific name and include the current time. However, the process might vary depending on the software or application you're using. Below are general instructions for Microsoft Excel and Google Sheets:

    ### Microsoft Excel:

    1. **Open Excel:**
    Open your Excel file.

    2. **Open Visual Basic for Applications (VBA):**
    - Press `Alt` + `F11` to open the Visual Basic for Applications (VBA) editor.

    3. **Insert a Module:**
    - In the VBA editor, right-click on the project for your workbook in the left sidebar.
    - Choose `Insert` > `Module` to insert a new module.

    4. **Paste the VBA Code:**
    - Copy and paste the following VBA code into the module:

    ```vba
    Sub SaveWithTime()
    Dim fileName As String
    Dim currentTime As String

    ' Get the current time in the format HHMMSS
    currentTime = Format(Now, "HHMMSS")

    ' Specify the file name with the current time
    fileName = "YourFileName_" & currentTime & ".xlsx"

    ' Save the workbook with the specified file name
    ThisWorkbook.SaveAs fileName
    End Sub
    ```

    - Replace `"YourFileName_"` with the desired part of your file name.

    5. **Close VBA Editor:**
    - Close the VBA editor.

    6. **Assign a Shortcut:**
    - Press `Alt` + `F8` to open the "Macro" dialog.
    - Select "SaveWithTime" and click "Options."
    - Assign a shortcut key (e.g., Clr+S) and click "OK."

    7. **Run the Macro:**
    - Press the shortcut key to run the macro and save the file with the specified name and current time.

Resources