Hello everyone,
I found some code that takes each sheet in the workbook and saves it into another workbook but the problem is if there are three sheets than that means three seperate workbooks.
I want all three worksheets in the same wrkbook. I cant just do save or save as because the master file will be saving the code as well and that would cause some problems.
Does anyone know how to help?
Thanks so much in advance!!
Latigo
Sub Copy_All_Sheets_To_New_Workbook()
Dim WbMain As Workbook
Dim Wb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
Application.ScreenUpdating = False
Application.EnableEvents = False
DateString = Format(Now, "mm-dd-yyyy")
Set WbMain = ThisWorkbook
FolderName = WbMain.Path & "\" & Left(WbMain.Name, Len(WbMain.Name) - 4) & " " & DateString
MkDir FolderName
For Each sh In WbMain.Worksheets
If sh.Visible = -1 Then
sh.Copy
Set Wb = ActiveWorkbook
' Make values from the formulas
' With Wb.Sheets(1).UsedRange
' .Value = .Value
' End With
'Wb.SaveAs FolderName _
'& "\" & Wb.Sheets(1).Name & ".xls"
'Wb.Close False
End If
Next sh
MsgBox "Look in " & FolderName & " for the files"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
I found some code that takes each sheet in the workbook and saves it into another workbook but the problem is if there are three sheets than that means three seperate workbooks.
I want all three worksheets in the same wrkbook. I cant just do save or save as because the master file will be saving the code as well and that would cause some problems.
Does anyone know how to help?
Thanks so much in advance!!
Latigo
Sub Copy_All_Sheets_To_New_Workbook()
Dim WbMain As Workbook
Dim Wb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
Application.ScreenUpdating = False
Application.EnableEvents = False
DateString = Format(Now, "mm-dd-yyyy")
Set WbMain = ThisWorkbook
FolderName = WbMain.Path & "\" & Left(WbMain.Name, Len(WbMain.Name) - 4) & " " & DateString
MkDir FolderName
For Each sh In WbMain.Worksheets
If sh.Visible = -1 Then
sh.Copy
Set Wb = ActiveWorkbook
' Make values from the formulas
' With Wb.Sheets(1).UsedRange
' .Value = .Value
' End With
'Wb.SaveAs FolderName _
'& "\" & Wb.Sheets(1).Name & ".xls"
'Wb.Close False
End If
Next sh
MsgBox "Look in " & FolderName & " for the files"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub