Copy Workbook & Save to Specific Location

torourke17

New Member
Joined
Jan 12, 2018
Messages
12
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello, need a little help, hopefully it's relatively easy. I currently have a code that saves my workbook to a specific folder I designated, naming the file based off a cell value. Unfortunately once I click the button to run the Macro it saves the current workbook to that location. I would prefer that it saves a copy to the pathway, keeping my 'active' workbook untouched and also closes the copy that was made. Below is the code I've been using.

Sub filename_cellvalue()
Dim Path As String
Dim filename As String
Path = "G:\xxx\yyy\bbb\etc"
filename = Range("B162")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsm", FileFormat:=52
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
.
Here is a macro that will accomplish your goal. You will need to edit some of the code to match your path, name, etc.

Code:
Option Explicit


Sub sveWrkBk()
Dim FName, x, y     As String
Dim FPath           As String


    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    x = Sheets("Sheet1").Range("C1").Value
    y = Sheets("Sheet1").Range("C2").Value
    Sheets("Sheet1").Range("C1:C2").Value = ""
    ActiveSheet.DrawingObjects.Visible = False
    FPath = "C:\Users\logit\Desktop\"          ''<--- Change SAVE DIRECTORY as required
    ThisWorkbook.SaveCopyAs Filename:=FPath & x & y & ".xlsm"
    
    'Application.Visible = False            '<-- Uncomment line if you want this workbook to close after saving
    'Application.Quit                       '<-- UntrueFalse
    ActiveSheet.DrawingObjects.Visible = True
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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