Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try
f ActiveSheet.Name = "SheetA" Then MsgBox "Hello" " wrote: 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If lcase(ActiveSheet.Name) = lcase("SheetA") Then MsgBox "Hello" End Sub -- Regards, Tom Ogilvy wrote in message oups.com... 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 ----- HTH, Sean. " wrote: 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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Toppers, Tom & Sean
Your suggestions helped Vinay |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Correct Syntax | Excel Discussion (Misc queries) | |||
Correct VBA syntax | Excel Discussion (Misc queries) | |||
Correct way to call active worksheet? | Excel Programming | |||
If...and... - can never get the syntax correct! | Excel Programming | |||
Can't get this syntax correct, please help. | Excel Programming |