Code to disable all message boxes without deleting them

  • Hi All,


    I am writing a piece of code to open & run macros looping through the files, but every code run individually has a message box at the end for "code was ran without incident". I was wondering whether there is a way to disable this message box so the code can run through multiple files without having to click the space bar? I do not want to remove this message box, because when the individual runs the code in one file it is useful to have the message box there. Also, I have tried to copy the code & rewrite without the message box but this is someone else's code & it is very complex meaning it jumps a lot between different modules for different purposes so it would take a while to go through every sub & repeat but without a message (error prone too). So, I was wondering is there another alternative which I can add into the below code to automatically disable/close message boxes? (screen updating/displays do not work)


  • The only way that I can think of is to add a boolean variable in each workbook that confirms the msgbox runs. This would be set to False from the code above.

  • The only way that I can think of is to add a boolean variable in each workbook that confirms the msgbox runs. This would be set to False from the code above.

    Could you please explain further how to do this ?

  • Attach an an example file that runs the main code and one of the files it opens. It doesn't need any confidential data

    One of the files it opens contains a lot of code which I don't believe is confidential but the file is pretty complex so it may have more info than I know. Is it possible to delete a thread once resolved?

  • I'd suggest you just amend the declaration of the macros that are run so they look like:


    Code
    Sub MacroName(Optional ShowMessages As Boolean = True)


    then amend the relevant msgbox lines so that they start with:


    Code
    If ShowMessages Then


    Then when you want to disable the messages from the calling code, simply pass the optional argument as False.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • We do not delete threads when resolved. This is a help forum that is free. If you want confidentiality then use our pay for help Forum - Hire Help

  • Ahh great thank you. For example:

    And in my file where I am trying to run all, I would set show messages = false?


  • No, you pass False as an argument:


    Code
    Application.Run "'" & xFileName & "'!SAP", False


    for example.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • No, you pass False as an argument:


    Code
    Application.Run "'" & xFileName & "'!SAP", False


    for example.

    Hi Rory,


    After searching & messing around I found in the code the following:

    Code
    If pBln_EnableFinalMsg Then
    MsgBox "KE5Z data were downloaded without incident."
    End If

    And this is defined as:


    Code
    Function FGetSAPDataZREP18_Bln(ByVal pBln_EnableFinalMsg As Boolean _
                                        ) As Boolean

    And this relates to the code I am calling from my first book. I will be calling SCallGetSAPDataZREP18 (). Please see below:


    Is there a way to set the the

    Code
    pBln_EnableFinalMsg

    As false/not activate the message from my code in the book I want to run them all? I have tried searching to understand byVal & whether theres a way to deactivate this in my file but I am not sure.


    Thanks,


    Mel

  • Could you not just run a find/replace to turn those lines into comments...



    ...and then reverse it when you're done?

    Thank you for your input! As this file will be run monthly (for approx 50 files), the find & replace method would require too much work & would be easier to remove the messages completely! Thanks for the input though!:)

  • It looks like you could just run the function directly using:


    Code
    Application.Run "'" & xFilename & "'!FGetSAPDataZREP18_Bln", True

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!