G
Guest
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
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