S
Simon Lloyd
Hi all, i have the code below for copying visible sheets to another
workbook, however i need it to omit copying one sheet (Week Selection),
i have tried If Sheets("Week Selection").Visible = True Then... but
couldnt get it to carry on without copying this sheet, when a sheet is
activated (made visible) if certain criteria is met it runs the code
below, my trouble is as a sheet is being made visible it is hiding Week
Selection so the are both visible at the time the code is being run!
Any ideas?
Sub Copy Visible Sheets To New Workbook()
Dim WbMain As Workbook
Dim Wb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
Ash = ActiveSheet.Name
Application.ScreenUpdating = False
Application.EnableEvents = False
DateString = Format(Now, "dd-mm-yyyy") & " Time " & Format(Now,
"hh-mm")
Set WbMain = ThisWorkbook
FolderName = WbMain.Path & "\" & Left(Ash, Len(Ash) - 0)
On Error Resume Next
MkDir FolderName
On Error GoTo 0
For Each sh In WbMain.Worksheets
If sh.Visible = -1 Then
sh.Copy
Set Wb = ActiveWorkbook
Wb.SaveAs FolderName _
& "\" & Wb.Sheets(1).Name & " " & DateString &
".xls"
Wb.Close False
End If
Next sh
MsgBox "Look in " & FolderName & " for the files"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
workbook, however i need it to omit copying one sheet (Week Selection),
i have tried If Sheets("Week Selection").Visible = True Then... but
couldnt get it to carry on without copying this sheet, when a sheet is
activated (made visible) if certain criteria is met it runs the code
below, my trouble is as a sheet is being made visible it is hiding Week
Selection so the are both visible at the time the code is being run!
Any ideas?
Sub Copy Visible Sheets To New Workbook()
Dim WbMain As Workbook
Dim Wb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
Ash = ActiveSheet.Name
Application.ScreenUpdating = False
Application.EnableEvents = False
DateString = Format(Now, "dd-mm-yyyy") & " Time " & Format(Now,
"hh-mm")
Set WbMain = ThisWorkbook
FolderName = WbMain.Path & "\" & Left(Ash, Len(Ash) - 0)
On Error Resume Next
MkDir FolderName
On Error GoTo 0
For Each sh In WbMain.Worksheets
If sh.Visible = -1 Then
sh.Copy
Set Wb = ActiveWorkbook
Wb.SaveAs FolderName _
& "\" & Wb.Sheets(1).Name & " " & DateString &
".xls"
Wb.Close False
End If
Next sh
MsgBox "Look in " & FolderName & " for the files"
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub