Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copying new activesheet after other activesheet is hidden?


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


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=553503

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copying new activesheet after other activesheet is hidden?

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"
wrote in message
...

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


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile:
http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=553503



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get ActiveSheet name in VB Geoff Lambert[_2_] Excel Programming 1 October 8th 04 02:25 PM
ActiveSheet.ShowAllData shows everything - way to have hidden _not_ show up? StargateFanFromWork Excel Programming 1 July 8th 04 04:33 AM
name of the activesheet rasta Excel Programming 1 October 3rd 03 09:49 PM
ActiveSheet.Name? Andrew Stedman Excel Programming 5 July 30th 03 01:17 PM
ActiveSheet Ron de Bruin Excel Programming 0 July 29th 03 04:59 PM


All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"