• Need explaining on 2 msgbox options. (Excel VBA)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Need explaining on 2 msgbox options. (Excel VBA)

    Author
    Topic
    #427300

    What does vbMsgBoxSetForeground + vbSystemModal do in an Excel msgbox? Help does not explain in detail.

    1. I know that modal forces the user to have to repond to the msgbox before they have access to the interface again. But I can see no difference whether the modal is on or off! If I do not use modal then the msgbox is still “modal” anyways???

    2. I have experimented with SetForground, and cannot see what its purpose is?

    TIA

    Viewing 0 reply threads
    Author
    Replies
    • #989700

      vbSystemModal keeps the message box in the foreground even if you switch to another application. In recent Windows versions, it doesn’t prevent you from working in that other application, however.

      I think vbMsgBoxSetForeground is intended for use in Automation (controlling Excel in VBA from another application); I’m not 100% sure about this.

      • #989704

        I tried it by starting Excel from Word and then showing a msgbox with this setting, but it remains tied to the Word window.

        If I recall correctly, these options don’t “take” for VBA, they belong to VB6, in which they seem to have an effect.

        • #989710

          Hi Jan,
          OK, so it is for use in VB only then. This is OK…I don’t use it anyways! Could you tell me (if you know) what its purpose is. Its just out of curiosity though!
          Tx

      • #989709

        I recall a Application Modal option on the msgbox too. Maybe that will prevent you from working in that other application. Tx for the reply.

        • #989721

          vbApplicationModal has the value 0, so it is used by default. There is actually no reason to use this constant explicitly. A message box is always modal in the application it is called in, i.e. while the message box is displayed, the user cannot do anything in the application, and code execution is halted.

          vbSystemModal prevented the user from working in other applications in 16-bit versions of Windows (Windows 3.11 and earlier). Microsoft decided that it wasn’t acceptable that one application could suspend all others on a truly multitasking system, so in 32 bit versions (Windows 95, Windows NT and later) it only keeps the message box in the foreground.

          • #989729

            Tx. This has clarified the Modal issue for this thread. Cheers Hans.

            Now I will see if any comments come through for the msgboxSetForeground option! In the mean time I googled and came up with this MS Page that shows an example of this argument. I still am unclear to the context of it though???
            See Sample Code.

            Another observation: When setting up a msgbox I always used msgbox “Prompt”, vbOKCancel + vbInformation + vbBlahBlah, “Title”, ….. (I use the + sign) BUT I see this sample code and other code I saw uses the OR operator.
            I see now difference in the result! I assume theirfore that either can be used?

            Tx

            • #989732

              1) The sample code you refer to is meant for a VB6 application. Jan Karel Pieterse already indicated that vbMsgBoxSetForeground is only useful in VB6, not in VBA. This, and all other examples I’ve seen are used when automating another applucation (Excel in this example) from VB6.

              2) If you write out the message box constants in binary, you’ll see why

              vbYesNo = decimal 4 = binary 00000100
              vbQuestion = decimal 32 = binary 00100000

              As you see, the 1s are in different positions. Hence the binary Or (which has 1 where either of the arguments has a 1) and the arithmetic + have the same result.

              Binary (00000100 Or 00100000) = binary 00100100 = decimal 36.
              Binary (00000100 + 00100000) = binary 00100100 = decimal 36.

            • #989737

              Wow Hans, you could have simply said they are the same. But tx for the indepth explanation. I do appreciate it!
              Cheers

    Viewing 0 reply threads
    Reply To: Need explaining on 2 msgbox options. (Excel VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: