LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default testing whether a sheet is present

The first time a workbook is opened, i want to replace 2 sheets (BBipads and
TBipads) with 2 other sheets (BBipads1 and TBipads1 respectively) then delete
BBipads1 and TBipads1. The '1' replacement sheets are inserted by a third
party program. On openings after the ffirst, I want to skip the copy/delete
process. My sub works the first time - when it does the copy and delete
processes. But on 2nd opening, it gives an error when it tries to select the
deleted sheets. I thought my tests for the presence of the sheets would avoid
such error but there must be something wrong here. Any help would be greatly
appreciated. Thanks,


Private Sub Workbook_Open()

' first time the book is opened, replace data sheets

Application.DisplayAlerts = False
Dim sh As Excel.Worksheet
On Error Resume Next
Set sh = xlApp.Worksheets("BBipads1")
On Error GoTo 0
If sh Is Nothing Then
Sheets("BBipads1").Select
Cells.Select
Selection.Copy
Sheets("BBipads").Select
Cells.Select
ActiveSheet.Paste
Sheets("BBipads1").Select
ActiveWindow.SelectedSheets.Delete
Else: End If

On Error Resume Next
Set sh = xlApp.Worksheets("TBipads1")
On Error GoTo 0
If sh Is Nothing Then
Sheets("TBipads1").Select
Cells.Select
Application.CutCopyMode = False
Selection.Copy
Sheets("TBipads").Select
Cells.Select
ActiveSheet.Paste
Sheets("TBipads1").Select
ActiveWindow.SelectedSheets.Delete
Else: End If
Application.DisplayAlerts = True

' set to welcome screen

Sheets("Welcome").Select

End Sub


--
Jeff
 
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
Locating if a Sheet is present in a workbook Shane Excel Discussion (Misc queries) 3 October 29th 09 08:20 PM
getting the sheet names present in a work book???? Reny J Joseph Thuthikattu Excel Programming 2 December 12th 04 05:30 AM
finding a value thats present more than once in a sheet monika Excel Programming 2 March 3rd 04 05:34 PM
testing if a sheet is protected John Wilson Excel Programming 0 September 9th 03 07:21 PM
Testing to see if a sheet name exists anita Excel Programming 1 September 4th 03 10:14 PM


All times are GMT +1. The time now is 10:59 AM.

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"