Home » excel » macos – Why does the prompt text not appear for my InputBox using VBA in Excel for Mac?

macos – Why does the prompt text not appear for my InputBox using VBA in Excel for Mac?

Posted by: admin April 23, 2020 Leave a comment

Questions:

I’ve been building a system that will keep track of student grades, using Excel. I’ve coded it under Windows, where everything works fine, but when I test it on the Mac version of Excel (the latest version, 15.24, I believe), the InputBoxes only show the title and the text box for the input data; the prompt text is not shown.
Here is an example of the code that I use to handle the InputBoxes:

On Error Resume Next
    assessmentName = Application.InputBox("Please enter a name for the new assessment:", "Enter assessment name")
    If assessmentName = "False" Then
        Exit Sub
    End If
Err.Clear

In this case, all that is displayed is the title ‘Enter assessment name’ and the text box where the user types the name.
Is there a difference in the way the Mac version of Excel deals with VBA code, that would cause this to happen? Are the problems a result of bad coding on my part, combined with the weaker VBA support that Excel seems to have on the Mac?

UPDATE: I’ve now labelled the arguments in the code like so:

On Error Resume Next
    assessmentName = Application.InputBox( _
                    Prompt:="Please enter a name for the new assessment:", _
                    Title:="Enter assessment name")
    If assessmentName = "False" Then
        Exit Sub
    End If
Err.Clear

Unfortunately, the prompt is still missing when I run the macro on the Mac version of Excel.

SECOND UPDATE: I’ve found the solution and posted it in an answer below.

How to&Answers:

I’ve found the answer, and am posting it here in the hope of helping somebody else who’s having the same problem. When I was reading this page I found the following comment:

Microsoft seems to love confusion, so you also have access to the InputBox method, which is a method of the Application object.

So it turns out that I was using Application.InputBox, when I should have been using simply InputBox.

The following code works, i.e. it displays the prompt as well as the input box and title:

On Error Resume Next
    assessmentName = InputBox( _
                    Prompt:="Please enter a name for the new assessment:", _
                    Title:="Enter assessment name")
    If assessmentName = "False" Then
        Exit Sub
    End If
Err.Clear

Answer:

Same problem with Excel Mac Version 16.20 packed with VBA Version 7.1.

Using InputBox alone does not work when using Type:=

Displays:

Compile error:
Named argument Type not found

Unfortunately Type:= only works with Application.InputBox

As a workaround you can see in the sample code below, I am using a combination of Title:= and Default:= to “Prompt” what needs to be entered.

Just another option until MS fixes this for Mac users.

By the way, it’s a handy little code snippet.

Sub ClearErrorsFromInputRange()
    ' Clear all cells containing errors
    Dim rRange As String
    On Error Resume Next
    rRange = Application.InputBox(Prompt:="Not Working On Mac", _
        Title:="Clear Errors From Range", Default:="J2:J4000", Type:=2)
    With Range(rRange)
        .SpecialCells(xlCellTypeConstants, xlErrors).Value2 = ""
    End With
End Sub