Macro to export several sheets to a new workbook then name it with wording and today's date

Melimob

Active Member
Joined
Oct 16, 2011
Messages
395
Office Version
  1. 365
Hi there

I seemed to have found macros that do part of what I need but I have no idea how to put it all together..

I need to export 4 worksheets named:
BELGIUM
GERMANY
UK
SUMMARY

to a new workbook in the same location each week and name it:

Weekly_Online_Adoption_TODAYSDATE.xlsx

Todays date is obviously the date I saved.

I know how to record a macro to do part (without the name) but each time I save Book1 may not be book1 so I need it to be dynamic!

Many thanks!
Melissa
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try

Code:
Sub test()
Sheets(Array("BELGIUM", "GERMANY", "UK", "Summary")).Copy
ActiveWorkbook.SaveAs Filename:="Weekly_Online_Adoption_" & Format(Date, "ddmmyyyy") & ".xlsx", FileFormat:=51
End Sub
 
Upvote 0
Hi Peter,

Thanks so much!! that works perfectly however could you also tell me 2 things that I forgot..

1) In the new workbook, can I also change the page layout theme colours to a saved theme template?
2) It is saving in My Documents, is there anyway I can get it saved to a particular folder?

Many thanks!
 
Upvote 0
For #1 try recording a macro whilst doing that manually to give you the code.

for #2 try like this

Rich (BB code):
ActiveWorkbook.SaveAs Filename:="C:\test\Weekly_Online_Adoption_" & Format(Date, "ddmmyyyy") & ".xlsx", FileFormat:=51
 
Upvote 0
wow - Peter, that worked wonderful thank you so much!!

re: point 1 - it doesn't record anything when choosing theme but it's no bother, only takes a sec manually!

cheers again!

Melissa
 
Upvote 0
Try

Code:
Sub test()
Sheets(Array("BELGIUM", "GERMANY", "UK", "Summary")).Copy
ActiveWorkbook.SaveAs Filename:="Weekly_Online_Adoption_" & Format(Date, "ddmmyyyy") & ".xlsx", FileFormat:=51
End Sub

Hi Peter, you kindly gave the above yesterday which worked great! I am trying to use it in another workbook and have simply adjusted the tab names and file names accordingly yet I'm getting an error...

It is highlighting the Sheets line?

Would you perhaps know why?

this is what I have:

Sub Export()
'
' Export Macro
'
Sheets(Array("ASIA Summary", "ASIA DETAIL", "EMEA Summary", "EMEA DETAIL")).Copy
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\motest\My Documents\WeeklyFile" & Format(Date, "ddmmyyyy") & ".xlsx", FileFormat:=51
End Sub
 
Upvote 0
Is it possible to edit the code so that the new sheet is saved as values instead of the formulas?

Thanks in advance!
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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