Save sheets in different folders

sweeneytime

Board Regular
Joined
Aug 23, 2010
Messages
183
Hi Guys,

I have been trying to adapt code I have already but with no success.

I want to save all sheets in a workbook that have "project reports" in A3.
Use the file path in D2, each sheet has a different file path.

HTML:
Sub SelectAll()
    Dim ws As Worksheet
    Dim bStarted As Boolean
 
 
 
    For Each ws In ActiveWorkbook.Worksheets
            If ws.Range("A3").Text = ("Project Reports") Then
                Call SaveSheets
            End If
    Next ws
 
 
End Sub
 
Sub SaveSheets()
   Dim iSheet As Integer
   Dim sPath As String
   Application.ScreenUpdating = False
   sPath = Range("D2").Value & "\"
 
      ActiveWorkbook.SaveAs sPath & ActiveSheet.Name
      ActiveWorkbook.Close savechanges:=False
 
   Application.ScreenUpdating = True
 
End Sub

The second part of the code was adapted from this.

HTML:
Sub SaveSheets1()
   Dim iSheet As Integer
   Dim sPath As String
   Application.ScreenUpdating = False
   sPath = Range("D2").Value & "\"
   For iSheet = Worksheets.Count - 13 To Worksheets.Count
      Worksheets(iSheet).Copy
      ActiveWorkbook.SaveAs sPath & ActiveSheet.Name
      ActiveWorkbook.Close savechanges:=False
   Next iSheet
   Application.ScreenUpdating = True
   MsgBox "Job is complete"
End Sub

I am a beginner when it comes to VBA so I am glad of any help!!

Thanks,
Alan
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Code:
Sub Save_Project_Reports()
    
    Dim ws As Worksheet
    
    Application.ScreenUpdating = False
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Range("A3").Text = "Project Reports" Then
            ws.Copy 'Copy the sheet to its' own workbook
            ActiveWorkbook.SaveAs Range("D2").Value & "\" & ActiveSheet.Name & ".xls"
            ActiveWorkbook.Close SaveChanges:=False
        End If
    Next ws
    Application.ScreenUpdating = True
    
    MsgBox "Job is complete"
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

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