Copying new activesheet after other activesheet is hidden?

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
 
N

Norman Jones

Hi Simon,

Try changing:
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


to

For Each sh In WbMain.Worksheets
If sh.Name <> "Week Selection" Then
If sh.Visible Then
sh.Copy
Set Wb = ActiveWorkbook
Wb.SaveAs FolderName & "\" & Wb.Sheets(1).Name _
& " " & DateString & ".xls"
Wb.Close False
End If
End If
Next sh

--
---
Regards,
Norman


"Simon Lloyd" <[email protected]>
wrote in message
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top