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)


  • 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
    1. Sub MacroName(Optional ShowMessages As Boolean = True)


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


    Code
    1. 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

  • 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
    1. 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
    1. Application.Run "'" & xFileName & "'!SAP", False


    for example.

    Hi Rory,


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

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

    And this is defined as:


    Code
    1. Function FGetSAPDataZREP18_Bln(ByVal pBln_EnableFinalMsg As Boolean _
    2. ) 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
    1. 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
    1. 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