Exporting Worksheet to save to specific location

scotthannaford1973

Board Regular
Joined
Sep 27, 2017
Messages
115
Office Version
  1. 2010
Platform
  1. Windows
Hi

I have the following code that saves an entire workbook to a specific folder and then adds the date and time to the file name. I am trying to amend it so that it only exports the current worksheet, saving it as .xlsx instead of .xlsm, not the entire worbook, but it does everything else that is shown. Would appreciate if someone can assist. TIA


Sub Auto_Save()
Dim savedate
savedate = Date
Dim savetime
savetime = Time
Dim formattime As String
formattime = Format(savetime, "hh.MM")
Dim formatdate As String
formatdate = Format(savedate, "YYYY.MM.DD")
Application.DisplayAlerts = False
Dim backupfolder As String
backupfolder = "M:\Acute\PMO\2018-19 CIP\0000. Archive\"
ActiveWorkbook.SaveCopyAs Filename:=backupfolder & formatdate & " " & formattime & " " & ActiveWorkbook.Name
ActiveWorkbook.Save
Application.DisplayAlerts = True
MsgBox "CIP Tracker backed up to " & backupfolder & " - check folder if needed!"
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try:
VBA Code:
Sub Auto_Save()
    Dim savedate, savetime, formattime As String, formatdate As String, backupfolder As String, srcWB As Workbook
    savedate = Date
    savetime = Time
    formattime = Format(savetime, "hh.MM")
    formatdate = Format(savedate, "YYYY.MM.DD")
    Set srcWB = ThisWorkbook
    Application.DisplayAlerts = False
    backupfolder = "M:\Acute\PMO\2018-19 CIP\0000. Archive\"
    ActiveSheet.Copy
    ActiveWorkbook.SaveAs Filename:=backupfolder & formatdate & " " & formattime & " " & srcWB.Name, FileFormat:=51
    Application.DisplayAlerts = True
    ActiveWorkbook.Close False
    MsgBox "CIP Tracker backed up to " & backupfolder & " - check folder if needed!"
End Sub
 
Upvote 0
Try:
VBA Code:
Sub Auto_Save()
    Dim savedate, savetime, formattime As String, formatdate As String, backupfolder As String, srcWB As Workbook
    savedate = Date
    savetime = Time
    formattime = Format(savetime, "hh.MM")
    formatdate = Format(savedate, "YYYY.MM.DD")
    Set srcWB = ThisWorkbook
    Application.DisplayAlerts = False
    backupfolder = "M:\Acute\PMO\2018-19 CIP\0000. Archive\"
    ActiveSheet.Copy
    ActiveWorkbook.SaveAs Filename:=backupfolder & formatdate & " " & formattime & " " & srcWB.Name, FileFormat:=51
    Application.DisplayAlerts = True
    ActiveWorkbook.Close False
    MsgBox "CIP Tracker backed up to " & backupfolder & " - check folder if needed!"
End Sub
Hi Mumps

thanks for that - unfortunately it flashes up an error when I run it - any ideas?

it doesn't like:
ActiveWorkbook.SaveAs Filename:=backupfolder & formatdate & " " & formattime & " " & srcWB.Name, FileFormat:=51



TIA
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    37.8 KB · Views: 29
Upvote 0
Try:
VBA Code:
Sub Auto_Save()
    Dim savedate, savetime, formattime As String, formatdate As String, backupfolder As String, srcWB As Workbook
    savedate = Date
    savetime = Time
    formattime = Format(savetime, "hh.MM")
    formatdate = Format(savedate, "YYYY.MM.DD")
    Set srcWB = ThisWorkbook
    Application.DisplayAlerts = False
    backupfolder = "M:\Acute\PMO\2018-19 CIP\0000. Archive\"
    ActiveSheet.Copy
    ActiveWorkbook.SaveAs Filename:=backupfolder & formatdate & " " & formattime & " " & Split(srcWB.Name, ".")(0) & ".xlsx", FileFormat:=51
    Application.DisplayAlerts = True
    ActiveWorkbook.Close False
    MsgBox "CIP Tracker backed up to " & backupfolder & " - check folder if needed!"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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