Hi. I have a userform that lets the user select an open workbook and make a few updates to the specific workbook's tabs. Some of the workbook tabs have a worksheet_activate event set and sometimes that event will run into an error (usually an unrelated subscript out of range error). I'm hoping there's a way to suppress the external book's worksheet_activate. I've tried turning enableevents off, but that doesn't seem to work as the error will still display. I also included a on error resume next in the userform's procedure, but that doesn't stop it either.
If it helps, below is the userform code where the external workbooks sheets are looped through for certain updates.
Code
Private Sub cboProcess_Click()
Dim wb As Workbook
Set wb = Workbooks(Me.cboOpenWBs.Value)
Dim sh As Worksheet
wb.Application.EnableEvents = False
Dim password As String
password = "admin"
If Me.chbCells.Value = True Then
If WorksheetExists2("API Extract") Then
For Each sh In wb.Sheets
If sh.Name = "results" Or sh.Name = "API Extract" Or sh.Name = "Auditor Setup" Or sh.Name = "API Write" Then
Else
With sh
.Unprotect password
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect password
End With
End If
Next sh
Else
For Each sh In wb.Sheets
With sh
.Unprotect password
.Cells.Locked = False
.Cells.SpecialCells(xlCellTypeFormulas).Locked = True
.Protect password
End With
Next sh
End If
End If
If Me.chbFooter.Value = True Then
Dim ctr As String, pub As String
ctr = Me.txtDocCtrl
pub = Me.txtPubDt
If WorksheetExists2("API Extract") Then
For Each sh In wb.Sheets
If sh.Name = "results" Or sh.Name <> "API Extract" Or sh.Name <> "Auditor Setup" Or sh.Name <> "API Write" Then
Else
With sh
.Unprotect password
.PageSetup.RightFooter = ctr & Chr(10) & pub
.Protect password
End With
End If
Next sh
Else
For Each sh In wb.Sheets
With sh
.Unprotect password
.PageSetup.RightFooter = ctr & Chr(10) & pub
.Protect password
End With
Next sh
End If
End If
wb.Application.EnableEvents = True
Dim foot As Variant
Dim upd As String
foot = wb.Sheets("Main").PageSetup.RightFooter
upd = Right(foot, Len(foot) - Application.WorksheetFunction.Find(Chr(10), foot))
If Me.chbCells.Value = True And Me.chbFooter.Value = True Then
MsgBox "Processing completed for the following... " & _
vbCrLf & "1) Formula cells have been protected on all sheets" & _
vbCrLf & "2) Document " & ctr & " has been updated with a " & _
"published date of " & upd, vbInformation, "Completed"
ElseIf Me.chbCells.Value = True And Me.chbFooter.Value = False Then
MsgBox "Processing completed for the following... " & _
vbCrLf & "1) Formula cells have been protected on all sheets" & _
vbInformation, "Completed"
ElseIf Me.chbCells.Value = False And Me.chbFooter.Value = True Then
MsgBox "Processing completed for the following... " & _
vbCrLf & "1) Document " & ctr & " has been updated with a " & _
"published date of " & upd, vbInformation, "Completed"
End If
Unload Me
End
End Sub
Display More