Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Correct syntax for Active Worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Correct syntax for Active Worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Correct syntax for Active Worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Correct syntax for Active Worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Correct syntax for Active Worksheet

Thanks Toppers, Tom & Sean
Your suggestions helped
Vinay



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct Syntax TeeSee Excel Discussion (Misc queries) 6 February 28th 08 01:36 AM
Correct VBA syntax Ken G. Excel Discussion (Misc queries) 3 December 7th 05 12:35 AM
Correct way to call active worksheet? Locutis Excel Programming 4 May 2nd 05 06:17 PM
If...and... - can never get the syntax correct! Darin Kramer Excel Programming 12 March 24th 05 04:18 PM
Can't get this syntax correct, please help. Sharlene England Excel Programming 4 December 1st 03 05:41 PM


All times are GMT +1. The time now is 09:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"