VBA script to copy of active workbook and add a timestamp (mm_dd_yyy) and place copied file in a specific folder

J7House1984

New Member
Joined
Oct 30, 2020
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am a beginner at VBA, I know enough to get myself stuck frequently. I am trying to write a VBA script, for archiving purposes, to write a copy of file and add a timestamp in this format (mm_dd_yyy) and place the copied file in a specific folder.

The location folder path is H:\fbqf9009\Documents\Campaigns\Campaign Reporting.

The end result would ideally be Filename mm_dd_yyy.xls


The script I have thus far is and I getting error messages. I know this is isn't everything I am trying to do in the script but I am stuck and need help.

VBA Code:
Sub SaveArchive()
Dim dt As String
WbName As String

WbName = "ActiveWorkbook.name"
dt = Format(CStr(Now), "mm_dd_yyyy")
ActiveWorkbook.SaveAs Filename:=WbName & dt
End Sub


Please help?!?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi,

You're close, but you missed a few things.

First, you MUST put a DIM statement in front of all variables you declare. You forgot it for WBName in line 3.

Here's a macro that should work for you which will save the open workbook in the current folder.

Sub SaveArchive()
Dim dt As String
Dim WBName As String

WBName = ActiveWorkbook.Name & " " & Format(Date, "mm-dd-yy")
ActiveWorkbook.SaveAs Filename:=WBName

End Sub

Hope this helps.

Bill B.
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,840
Members
449,193
Latest member
MikeVol

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