Macro - That can save a file called "Master pack" and save a copy of this file in the same location with a new name picked from cell in active wb

Luke1690

Board Regular
Joined
Jul 26, 2022
Messages
106
Office Version
  1. 2016
Platform
  1. Windows
Morning guys, really need help with this one been looking every where for a solution.

i need a macro that can save a copy of a file "Master pack" and then save a copy of that file, renaming it with a cell value.

please if someone could point me in the right direction or give me the code.

would really appreciate it.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Something like the below might work....
This saves the file in a directory as defined with a Year/Month Structure, if not needed drop FromatDate in CheminDest

VBA Code:
Sub MasterPack()
Dim WS As Worksheet, CheminDest As String, fNAME As String

'create directories as needed
    On Error Resume Next
    CheminDest = "C:\Users\add_your_directory_here" & Year(Date) & "\"  
    MkDir CheminDest
    CheminDest = CheminDest & Format(Date, "MMM YY") & "\" 
    MkDir CheminDest
    On Error GoTo 0

    fNAME = Range("D1") - 'This will take the value in Cell D1 and use this for the file name

'Copies the sheets to a new workbook:
    Sheets(Array("Sheet1", "Sheet2")).Copy
    Sheets("Sheet1").Name = "SomethingElse"
    Sheets("Sheet2").Name = "SomethingElse2"

    With ActiveWorkbook
        For Each WS In .Worksheets  'Goes through each worksheet in new workbook
        'Writes the values
        Next WS
        
        
        .SaveAs Filename:=CheminDest & fNAME & Format(Date, "yyyymmdd") & ".xls"
        .Close False
    End With
        
    MsgBox "Text file has been saved ", vbInformation, "Data backup"

End Sub
 
Upvote 0
Something like the below might work....
This saves the file in a directory as defined with a Year/Month Structure, if not needed drop FromatDate in CheminDest

VBA Code:
Sub MasterPack()
Dim WS As Worksheet, CheminDest As String, fNAME As String

'create directories as needed
    On Error Resume Next
    CheminDest = "C:\Users\add_your_directory_here" & Year(Date) & "\" 
    MkDir CheminDest
    CheminDest = CheminDest & Format(Date, "MMM YY") & "\"
    MkDir CheminDest
    On Error GoTo 0

    fNAME = Range("D1") - 'This will take the value in Cell D1 and use this for the file name

'Copies the sheets to a new workbook:
    Sheets(Array("Sheet1", "Sheet2")).Copy
    Sheets("Sheet1").Name = "SomethingElse"
    Sheets("Sheet2").Name = "SomethingElse2"

    With ActiveWorkbook
        For Each WS In .Worksheets  'Goes through each worksheet in new workbook
        'Writes the values
        Next WS
       
       
        .SaveAs Filename:=CheminDest & fNAME & Format(Date, "yyyymmdd") & ".xls"
        .Close False
    End With
       
    MsgBox "Text file has been saved ", vbInformation, "Data backup"

End Sub
I've found somthing that works for me I will post the code soon. Thank you for your response though 👍
 
Upvote 0

Forum statistics

Threads
1,215,821
Messages
6,127,059
Members
449,356
Latest member
tstapleton67

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top