+ Reply to Thread
Results 1 to 3 of 3

Worksheet message box accessed manually and using macros

Hybrid View

  1. #1
    Registered User
    Join Date
    01-24-2014
    Location
    Norwich, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Worksheet message box accessed manually and using macros

    Hi all,

    I've got a workbook which holds lots of information on a number of worksheets. I've used shapes/macros to create buttons on sheet 1. These buttons select the appropriate worksheet and filters information to make it simple for the layman to find what they want.

    Navigating manually using the worksheet tabs won't reset the filters and may make subsequent searches incomplete/fail so I've added a message box to remind the user to navigate using the buttons.

    Is there anyway of identifying if the worksheet was selected using one of the macros and skipping the message box?? Ie. can we treat a manual click differently to selecting using a macro?

    Thanks in advance.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Worksheet message box accessed manually and using macros

    Hi Steve,

    You may be able to do what you want by using a global variable to indicate whether a sheet was activated by Macro or Manually.

    Try the following code in the ThisWorkbook Module:
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    
      If bSheetActivatedByMacro = True Then
        MsgBox "Workbook_SheetActivate() triggered BY MACRO on '" & Sh.Name & "'" & vbCrLf & _
               "No Warning message needed."
      Else
        MsgBox "Workbook_SheetActivate() triggered MANUALLY on '" & Sh.Name & "'" & vbCrLf & _
               "DANGER WILL ROBINSON."
      End If
    End Sub

    Try the following code in an ordinary module:
    Option Explicit
    Public bSheetActivatedByMacro As Boolean
    
    Sub CommandButton1_Click()
      bSheetActivatedByMacro = True
      Sheets("Sheet2").Select
      
      '''''
      'your other code here
      '''''
      
      bSheetActivatedByMacro = False
      
    
    End Sub
    Code tested and working in Excel 2003. When a sheet is selected manually, the WARNING PATH is activated. When a sheet is selected by Macro, the NO WARNING path is activated.

    Lewis

  3. #3
    Registered User
    Join Date
    01-24-2014
    Location
    Norwich, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Worksheet message box accessed manually and using macros

    Thanks Lewis, I'm back in the office today so I'll give it a try.

    Thanks again... Steve

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Error Message When Adding Named Range Manually
    By chergh in forum Excel General
    Replies: 7
    Last Post: 01-23-2013, 06:31 AM
  2. Replies: 5
    Last Post: 03-24-2012, 06:52 AM
  3. Replies: 1
    Last Post: 01-18-2012, 06:59 PM
  4. Replies: 0
    Last Post: 10-30-2009, 02:52 PM
  5. Emailing worksheet accessed from a website???
    By mickiedevries in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2007, 03:12 PM

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