Save a Closed Workbook with new name in New Location

rhombus4

Well-known Member
Joined
May 26, 2010
Messages
586
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I know I can save an open/active workbook using code below.

What I want to do is Copy a closed workbook and Save a Copy into a New Location adding the Date

i.e If Closed workbook is Called MainDoc.xls and is located in C:\MainDoc.xls

I want it copied to my documents and add today's date and full time in case it is copied at same time e.g. C:\MyDocs\Maindoc 25-06-20 14:06:22.xls



VBA Code:
Dim wbookstring As String
wbookstring = "C:\Copy.xlsx"
ActiveWorkbook.SaveAs filename:=wbookstring
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You will have to set the Reference to use Microsoft Scripting. You also wont get the format in the way you want for time.

VBA Code:
Sub CopyFile()
Dim OfSO As Object
Set OfSO = CreateObject("Scripting.FileSystemObject")
Call OfSO.CopyFile("C:\MainDoc.xls", "C:\MyDocs\Maindoc " & Format(Date, "DD - MM - YY") & ".xls")

End Sub
 
Upvote 0
Thanks Trevor, but is there another way without using Microsoft SCripting
 
Upvote 0
Try this

VBA Code:
Sub CopyFile2()
Dim sFolder, dFolder As String
sFolder = "C:\"
dFolder = "C:\MyDocs\"
FileCopy sFolder & "MainDoc.xls", dFolder & "MainDoc " & Format(Now(), "DD mmm YY") & ".xls"
End Sub
 
Upvote 0
Thanks again
wasn't sure if it would cause error when saving as same name but it worked ok!

but did edit the line to get time without : i.e. 161723

& Format(Now(), "DD mmm YY hhmm:ss") & ".xlsx"
 
Upvote 0

Forum statistics

Threads
1,214,378
Messages
6,119,188
Members
448,873
Latest member
jacksonashleigh99

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