Msgbox if sheet opened manually, but not when called from another sheet

Richard U

Active Member
Joined
Feb 14, 2006
Messages
406
Office Version
  1. 365
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
I have a worksheet that is sometimes opened manually, and sometimes opened through automation.

I want to display a messagebox to the user if they opened it manually, but not if it was called by another spreadsheet.

Is there a way to set a flag or to send a value through application.run to do this?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hello Richard,
You need to put codes in the few places
I hope so this example will demonstrate that and help you to understand...
VBA Code:
Private Sub Workbook_Open()
        
    Call VariableInitiating
        
End Sub


'this goes to the Sheet1 module
Private Sub Worksheet_Activate()
    
    If varCheck = "The sheet is selected automatically." Then
        MsgBox "The sheet is selected automatically."
    Else
         MsgBox "The sheet is selected manually."
    End If
    varCheck = "The sheet is selected automatically."
    
End Sub


Private Sub Worksheet_Deactivate()
    
    varCheck = ""
    
End Sub


'this goes to the Sheet2 module
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    varCheck = "The sheet is selected automatically."
    Sheets(1).Activate
    
End Sub

'this goes to the standard module
Public varCheck As String

Sub VariableInitiating()

    varCheck = ""
    
End Sub
 
Upvote 0
Hello Richard,
You need to put codes in the few places
I hope so this example will demonstrate that and help you to understand...
Ach! Sorry, I meant workbook, not worksheet
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,025
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top