Michi
Michi

Reputation: 5471

Scrolling while message box is running

I have the following macro to show a message box to the user:

Sub Messageboxtest()
Test = MsgBox("Do you want to continue", vbYesNo)
If Answer = vbYes Then
Sheets(1).Range("A2").Value = 1
Else
End If
End Sub

The macro itself works perfectly. However, once the message box is shown on the excel screen the user cannot scroll down in the Excel File anymore.

For an input box I know there is the function Application.InputBox but is there also something like Application.MessageBox?

Upvotes: 0

Views: 2024

Answers (2)

CommonSense
CommonSense

Reputation: 4482

There's API alternative! Declare in a top of module this function:

#If VBA7 Then
    Public Declare PtrSafe Function ModelessMsgBox Lib "User32" Alias "MessageBoxA" (Optional ByVal hWnd As Long, _
            Optional ByVal prompt As String, _
            Optional ByVal title As String, _
            Optional ByVal buttons As Long) As Long
#Else
    Public Declare Function ModelessMsgBox Lib "User32" Alias "MessageBoxA" (Optional ByVal hWnd As Long, _
            Optional ByVal prompt As String, _
            Optional ByVal title As String, _
            Optional ByVal buttons As Long) As Long
#End If

And use it like this:

Call ModelessMsgBox(prompt:="MsgBox!!!!", buttons:=vbYesNo)

However, this MsgBox stops code execution (when modeless forms doesn't, dooming you to use another garbage set of global/static variables and/or to supress events just to control execution flow), so it can be used like this:

If ModelessMsgBox(prompt:="MsgBox!!!!", buttons:=vbYesNo) = vbYes Then
    'do smth
Else
    'do smth else
End If

More here

Upvotes: 0

Vinicius B
Vinicius B

Reputation: 162

There is not a application.MessageBox function just the MsgBox, but you can create a form that looks like a MsgBox and set the ShowModal property to False

Upvotes: 3

Related Questions