Correct syntax for Active Worksheet

V

vvaidya

Hello:
I am trying to write VBA code to display a message in the Workbook,
BeforePrint event.
I have three worksheets in the workbook, named SheetA, SheetB, and
SheetC.

I want a different message to show depending upon whether SheetA is the
active sheet, or SheetB or SheetC

The code would look something like this:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet = Sheets("SheetA") Then MsgBox "Hello"
etc etc
End Sub

Obviously, I am not using the correct syntax "ActiveSheet" as it is
giving me an error.

I would appreciate if you could help me with the correct syntax

TIA

Vinay
 
G

Guest

Hello Vinay,

Try this ...

-----

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Select Case ActiveSheet.Name
Case "Sheet1"
MsgBox ("Insert message for Sheet1 here.")
Case "Sheet2"
MsgBox ("Insert message for Sheet2 here.")
Case "Sheet3"
MsgBox ("Insert message for Sheet3 here.")
Case Else
MsgBox ("Some other Sheet is currently active. Insert message
here.")
End Select
End Sub
 
T

Tom Ogilvy

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If lcase(ActiveSheet.Name) = lcase("SheetA") Then MsgBox "Hello"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top