+ Reply to Thread
Results 1 to 5 of 5

Correct syntax for Active Worksheet

  1. #1

    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. #2
    Toppers
    Guest

    RE: Correct syntax for Active Worksheet

    Try

    f ActiveSheet.Name = "SheetA" Then MsgBox "Hello"

    "[email protected]" 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. #3
    Tom Ogilvy
    Guest

    Re: 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

    <[email protected]> wrote in message
    news:[email protected]...
    > 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. #4
    Sean Connolly
    Guest

    RE: 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.

    "[email protected]" 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. #5

    Re: Correct syntax for Active Worksheet

    Thanks Toppers, Tom & Sean
    Your suggestions helped
    Vinay


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1