+ Reply to Thread
Results 1 to 7 of 7

Ignore message boxes from other macro

Hybrid View

  1. #1
    Registered User
    Join Date
    12-14-2017
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    8

    Ignore message boxes from other macro

    Hi,
    I have a macro on an excel sheet that asks for confirmation before editing a cell and it works just fine. The code I use is:
     Option Explicit
       Dim OldValue As Variant
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        
        
        ' COMPLICATION DATA MSG BOXES
        
           If Not Intersect(Target, Range("C12:C23")) Is Nothing Then
            Application.EnableEvents = False
            Select Case MsgBox("This parameter is taken from a synthesis of the available published evidence (see the info section for details). Do you want to continue?", _
                               vbYesNo Or vbQuestion Or vbDefaultButton1, "Confirm change...")
                Case vbYes
                    GoTo exit_handler
                Case vbNo
                    Target.Value = "=Baseline_comp_PMLSE"
            End Select
        End If
        
           If Not Intersect(Target, Range("E12:E23")) Is Nothing Then
            Application.EnableEvents = False
            Select Case MsgBox("This parameter is taken from a synthesis of the available published evidence (see the info section for details). Do you want to continue?", _
                               vbYesNo Or vbQuestion Or vbDefaultButton1, "Confirm change...")
                Case vbYes
                    GoTo exit_handler
                Case vbNo
                    Target.Value = "=comp_PMLSE*risk_ratios_comp_2_vs_PMLSE"
            End Select
        End If
    
        If Not Intersect(Target, Range("G12:G23")) Is Nothing Then
            Application.EnableEvents = False
            Select Case MsgBox("This parameter is taken from a synthesis of the available published evidence (see the info section for details). Do you want to continue?", _
                               vbYesNo Or vbQuestion Or vbDefaultButton1, "Confirm change...")
                Case vbYes
                    GoTo exit_handler
                Case vbNo
                    Target.Value = "=comp_PMLSE*risk_ratios_comp_3_vs_PMLSE"
            End Select
        End If
    
    exit_handler:
        Application.EnableEvents = True
    End Sub
    
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        OldValue = Target.Value
    End Sub
        End If
    Now, what I'm trying to do is to write another macro that allows to reset the cells to the original values if they are modified. The new code is:

    Sub cinical_data_reset()
    '
    ' cinical_data_reset Macro
    '
    Answer = MsgBox("Are you sure you want to continue?", vbYesNoCancel + vbInformation, "Application Message")
    
    
    
    If Answer = vbYes Then Else Exit Sub
    
    '
        Range("C8:C9").FormulaR1C1 = "=baseline_comp_PMLSE"
        Range("E8:E9").FormulaR1C1 = "=comp_PMLSE*risk_ratios_comp_2_vs_PMLSE"
        Range("G8:G9").FormulaR1C1 = "=comp_PMLSE*risk_ratios_comp_3_vs_PMLSE"
       
       
    
    End Sub
    Obviously, when I run this second macro, the msg boxes from the first macro appear (as many as the number of ranges modified...). Question is: Do any idea on how I can make the second macroto ignore the first message boxes?

    Thanks a lot for your help

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Ignore message boxes from other macro

    Hello Carlin_123,

    Your issue could become a long drawn out effort to try and resolve, without a sample Workbook with all the Code and Named Ranges you are using.

    So, please attach a sample workbook.

    Make sure there is just enough data to demonstrate your need.

    Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate.

    Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Registered User
    Join Date
    12-14-2017
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    8

    Re: Ignore message boxes from other macro

    hello,
    here an attached sample file. Basically, there are two macros. The first one asks for confirmation before editing the pink cells. The reset button restores the original values if these have been changed.
    I'm trying to make that the reset macro ignore the message box that appears because of the first macro
    Attached Files Attached Files

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Ignore message boxes from other macro

    Try this.
    Sub cinical_data_reset()
    '
    ' cinical_data_reset Macro
    '
    
        Answer = MsgBox("Are you sure you want to continue?", vbYesNoCancel + vbInformation, "Application Message")
    
    
    
        If Answer <>  vbYes Then Exit Sub
    
        Application.EnableEvents = False
    '
        Range("C8:C9").FormulaR1C1 = "=baseline_comp_PMLSE"
        Range("E8:E9").FormulaR1C1 = "=comp_PMLSE*risk_ratios_comp_2_vs_PMLSE"
        Range("G8:G9").FormulaR1C1 = "=comp_PMLSE*risk_ratios_comp_3_vs_PMLSE"
       
        Application.EnableEvents = True
    
    End Sub
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    12-14-2017
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    8

    Re: Ignore message boxes from other macro

    hi Norie, thanks, I had already tried to use Application.EnableEvents, but with no results. My guess is that it works for "system" message boxes but not for message boxes prompted by other subroutines.

  6. #6
    Registered User
    Join Date
    12-14-2017
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    8

    Re: Ignore message boxes from other macro

    Hello,
    I just figured out how to do this. Rather than using a macro to warn against modification of cells values, I used validate data with a custom formula + a warning message error. It works fine and does not interact with the "reset values" macro

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Ignore message boxes from other macro

    Hello Carlin_123,

    Any reason why you could not use it just with the module, and exclude the Worksheet_Change Event?

    Regards.
    Attached Files Attached Files

+ 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. [SOLVED] Macro to ignore merge cell message
    By Ramzes in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-18-2017, 11:35 AM
  2. [SOLVED] VBA to Automatically Allow/Ignore Microsoft Outlook Message When Executing Macro from Exce
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2014, 06:00 PM
  3. Prevent message boxes from another macro from popping up
    By sczerniak in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 07-11-2013, 02:11 PM
  4. Clearing message boxes from screen as macro runs
    By prestopr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2013, 08:34 PM
  5. Disabling the message boxes of another file that will open when Macro executed
    By mr_horhe in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-16-2012, 06:04 AM
  6. [SOLVED] Help in Adding Message Boxes to the Macro
    By swathidas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-02-2012, 07:52 PM
  7. [SOLVED] Message Boxes in Reset Macro
    By amotto11 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 05-29-2012, 11:53 AM

Tags for this Thread

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