Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 431
- Office Version
- 365
- Platform
- Windows
- Mobile
When I save this workbook under a different name and folder all the worksheets disappear how can I avoid this??
End Sub
VBA Code:
Private Sub BO_Report_Yrs()
Dim dte As Date
Dim numericalDate As Integer
Dim sourceDir As String
Dim year As Integer
Dim Wb As Workbook
Dim Folder_exists As String
Dim FullFileName As String
Dim File_Name As Variant
Dim FolderPath As String
Dim FilePath As String
Dim ws As Worksheet
Dim Rng As Range
Set ws = ActiveSheet
If ws.Name <> "Summary" And ws.Name <> "Trend" And ws.Name <> "Supplier BO" And ws.Name <> "Dif Depot" _
And ws.Name <> "BO Trend WO" And ws.Name <> "BO Trend WO 2" And ws.Name <> "Different Depot" Then
Set Wb = Workbooks.Add
year = Trim(Str(Format(Date, "yyyy"))) + 1
dte = Now()
numerical_date = Int(CDbl(dte))
sourceDir = "S:\PURCHASING\Stock Control\Alton"
Folder_exists = Dir(sourceDir & "\" & year, vbDirectory)
If Folder_exists = "" Then
MkDir sourceDir & "\" & year
Folder_exists = Dir(sourceDir & "\" & year, vbDirectory)
End If
FilePath = "Alton Back Order"
FullFileName = Format(Now(), "yyyy") + 1 & " " & FilePath
FolderPath = sourceDir & "\" & year & "\" & FullFileName
Wb.SaveAs FolderPath
For Each ws In Wb.Worksheets
Set Rng = ws.Range("A2").CurrentRegion.Select
Selection.Clear
Next ws
End If
End Sub