Export Current Worksheet - not the entire workbook

scotthannaford1973

Board Regular
Joined
Sep 27, 2017
Messages
110
Office Version
  1. 2010
Platform
  1. Windows
hi

I have some simple VB that will back up an entire workbook to a specific location, with a file name that includes the time and date of saving... that's all good... but I'd like to add a button to a number of worksheets that will allow for that single sheet to be exported to a specific location (say H:/ ) and include the worksheet name, date and time in the file name.

As I need this button to be on multiple sheets, so any of them can be exported individually, I assume it's possible to create the VBA with ActiveSheet built in.

Guidance, hugely appreciated! So - to summarise:

  1. export current, active sheet
  2. to a specific folder H:/
  3. with worksheet name, date and time

and in the spirit of sharing, this is the code i use for backing up the entire workbook:

Sub SaveToArchive()

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\ICT\Digital Programme and Projects\00 - Projects and Workstreams\003 - Roadmap Resourcing and Scheduling\000 - Archive\"
ActiveWorkbook.SaveCopyAs Filename:=backupfolder & formatdate & " " & formattime & " " & ActiveWorkbook.Name
ActiveWorkbook.Save
Application.DisplayAlerts = True
MsgBox "The file has been backed up to " & backupfolder & " - check folder if needed!"

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
VBA Code:
    backupfolder = "M:\Acute\ICT\Digital Programme and Projects\00 - Projects and Workstreams\003 - Roadmap Resourcing and Scheduling\000 - Archive\"
     ActiveSheet.Copy     'or .move
     ActiveWorkbook.SaveAs Filename:=backupfoler & Format(Now, "yyyymmdd hhmmss ") & Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4), FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 
Upvote 0
Hi

I have used your code to amend the backup folder / file name etc as below - but it still saves with the workbook name, rather than the sheet... getting closer though!




Sub ExportCurrentSheet()

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 = "H:\"
ActiveSheet.Copy 'or .move
ActiveWorkbook.SaveAs Filename:=backupfolder & Format(Now, "yyyymmdd hhmmss ") & Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4), FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
MsgBox "The file has been backed up to " & backupfolder & " - check folder if needed!"

End Sub
 
Upvote 0
Rich (BB code):
ActiveSheet.Copy 'or .move
ActiveWorkbook.SaveAs Filename:=backupfolder & Format(Now, "yyyymmdd hhmmss ") & ActiveSheet.Name, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 
Upvote 0
Rich (BB code):
ActiveSheet.Copy 'or .move
ActiveWorkbook.SaveAs Filename:=backupfolder & Format(Now, "yyyymmdd hhmmss ") & ActiveSheet.Name, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

perfect - thanks!
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

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