VBA Message Box - restrict to one occurrence

mizogy

New Member
Joined
Jul 5, 2011
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hi All

I have a simple msgbox macro which is called upon each time a worksheet is activated. Users could select any worksheet in any particular order at any given time. Currently, the message box appears several times over should the user interchange between different sheets in the workbook. What I would like to be able to do, is restrict the macro containing the msgbox appearing from appearing again after one occurrence in the entire workbook. Help would be appreciated. Am I able to define the macro itself as variable so it only loops once?

Private Sub Worksheet_Activate()

Call MsgBox_Governance

End Sub


Sub MsgBox_Governance()

MsgBox "Governance:" & vbCrLf & vbCrLf & _

"Please ensure sign-off is obtained before proceeding", vbInformation, "User Information"

End Sub

Best, Mizogy
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi,
see if this update to your code will do what you want

VBA Code:
Sub MsgBox_Governance()
    Static showonce As Long
    
    If showonce <> xlOff Then
        MsgBox "Governance:" & vbCrLf & vbCrLf & _
               "Please ensure sign-off Is obtained before proceeding", vbInformation, "User Information"
        showonce = xlOff
    End If
    
End Sub

Dave
 
Upvote 0
Solution
Hi @mizogy

In your sheet module, change your code to the following code:
VBA Code:
Public isactivated As Boolean

Private Sub Worksheet_Activate()
  If isactivated = True Then Exit Sub
  isactivated = True
    
  Call MsgBox_Governance
End Sub

Sub MsgBox_Governance()
  MsgBox "Governance:" & vbCrLf & vbCrLf & _
    "Please ensure sign-off is obtained before proceeding", vbInformation, "User Information"
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
 
Upvote 0
Hi,
see if this update to your code will do what you want

VBA Code:
Sub MsgBox_Governance()
    Static showonce As Long
   
    If showonce <> xlOff Then
        MsgBox "Governance:" & vbCrLf & vbCrLf & _
               "Please ensure sign-off Is obtained before proceeding", vbInformation, "User Information"
        showonce = xlOff
    End If
   
End Sub

Dave
Perfect - that worked. Thank you, appreciated.
 
Upvote 0
Hi @mizogy

In your sheet module, change your code to the following code:
VBA Code:
Public isactivated As Boolean

Private Sub Worksheet_Activate()
  If isactivated = True Then Exit Sub
  isactivated = True
   
  Call MsgBox_Governance
End Sub

Sub MsgBox_Governance()
  MsgBox "Governance:" & vbCrLf & vbCrLf & _
    "Please ensure sign-off is obtained before proceeding", vbInformation, "User Information"
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
Thank you, appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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