Macro Save workbook to current month folder in path

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
626
Office Version
  1. 2016
Platform
  1. Windows
Code:
Sub CopyActiveSheet()Dim ws As Worksheet
Dim wb As Workbook
Dim Pth As String
Pth = ActiveWorkbook.Path & "\"
Set ws = ActiveSheet
ws.Copy
With ActiveWorkbook
ws.Cells.Copy .Sheets(1).Range("A1")
    ActiveWorkbook.SaveAs Filename:= _
        "[COLOR=#ff0000]K:\Work\Admin\Schedule\September\14.xlsx"[/COLOR], FileFormat _
        :=xlOpenXMLWorkbook, CreateBackup:=False
End With
ActiveWorkbook.Close False
End Sub

I have the Folders for each month in path "K:\Work\Admin\Schedule" what I'm trying to accomplish is that for it to automatically select the current month folder in that path and save the file as sheet name. As shown above I put the Month path and sheet name 14.

any help is greatly appreciated
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
How about
Code:
"K:\Work\Admin\Schedule\" & format(date,"mmmm") & "\" & activesheet.name & ".xlsx"
 
Upvote 0
Thanks Fluff. Is there a way to change the above code to copy selected Sheet instead of activeSheet without having to specify the sheet name in code.
 
Upvote 0
Not sure what you mean, there will only be one sheet in the new workbook, therefore it will be the active sheet.
 
Upvote 0
not in the new workbook. The current workbook has 10 sheets and the above code copies the activesheet to new workbook. Instead of active sheet I want to be able to Select few sheets and copy them to new workbook. so If i Select sheet 14, 15, 16 ,17 i what to us the above code to copy those to new workbook. without specify the sheet name to copy in the code so avoid using Sheets(Array("14", "15", "16", "17")).Copy.


 
Upvote 0
You can use
Code:
ActiveWindow.SelectedSheets.Copy
To copy all the selected sheets to a new workbook.
 
Upvote 0
Sub CopyActiveSheet()Dim ws As WorksheetDim wb As Workbook
Dim Pth As String
Pth = ActiveWorkbook.Path & ""
Set ws = ActiveSheet
ws.Copy
With ActiveWorkbook
ws.Cells.Copy .Sheets(1).Range("A1")
ActiveWorkbook.SaveAs Filename:= _
"K:\Work\Admin\Schedule" & format(date,"mmmm") & "" & activesheet.name & ".xlsx", FileFormat _
:=xlOpenXMLWorkbook, CreateBackup:=False
End With
ActiveWorkbook.Close False End Sub

Where would I place that and Would I need to remove whats in Red
 
Upvote 0
Like
Code:
Sub CopyActiveSheet()

Dim ws As Worksheet
Dim wb As Workbook
Dim Pth As String
Pth = ActiveWorkbook.Path & ""
ActiveWindow.SelectedSheets.Copy
With ActiveWorkbook
ActiveWorkbook.SaveAs Filename:= _
"K:\Work\Admin\Schedule" & Format(Date, "mmmm") & "" & ActiveSheet.Name & ".xlsx", FileFormat _
:=xlOpenXMLWorkbook, CreateBackup:=False
End With
ActiveWorkbook.Close False
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,986
Members
452,541
Latest member
haasro02

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