View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Run code conditional on sheet visibility

Try this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim runflag As Boolean
runflag = False
For x = 1 To Worksheets.Count
If Worksheets(x).Visible Then
Count = Count + 1
If Worksheets(x).Name = "LogGraph3" Then runflag = True
End If
Next
If Not runflag Then
Exit Sub
Else
If runflag And Count < 2 Then
Exit Sub
End If
End If
'some code
End Sub

Mike

"Sandy" wrote:

Hi
I have a situation whereby if sheet "LogGraph3" is the only sheet visible
then I do not require the Workbook_BeforeClose to run, how do I incorporate
that into the following.

******Sub Starts******
Sub Workbook_BeforeClose(Cancel As Boolean)

If Sheets("LogGraph3") 'is the only visible sheet' Then
GoTo EarlyEnd

Else
Do closing code
End If

EarlyEnd:
Some Code

End Sub
******Sub Ends*******

Thanks
Sandy