对于 Mac 15,Excel 上的 Application.InputBox 中未出现提示

Prompt doesn't appear in Application.InputBox on Excel for Mac 15

这是我的代码:

Sub demo1()
    Dim Rng1 As Range
    Set Rng1 = Application.InputBox("The Prompt", "The Dialog Title", Type:=8)
End Sub

这是 Excel 上 Windows 的结果(我还单击了一个单元格以添加引用):

这是 Excel 上 Mac 的结果(我点击了一个单元格,如上所述):

我使用的是版本 15。简单地说,我在 Excel 上没有看到 The Prompt for Mac。 表明人们已经能够使用普通的 InputBox(而不是 Application.InputBox)作为解决方法,但我需要增强版本,因为用户需要单击单元格范围,并且设置的变量必须是范围对象。普通的 vb InputBox 无法做到这一点。提前感谢您的任何建议。

我在这里四处寻找解决方案,但找不到。 Mac 对话框似乎根本不包含两个不同的部分(标题+提示)。我已经创建了一个解决方法,我将 post,如果有人遇到同样的问题,它可能会有用。但如果有人能想出更好的解决方案,我会备注答案。

首先我们检查我们是在 PC 上还是在 Mac 上:

On Error Resume Next
If Val(Application.Version) = Int(Val(Application.Version)) Then
    theOs = 0 'whole version number = PC
Else
    theOs = 1 'version number with decimal = Mac
End If
If Err.Number <> 0 Then
    Err.Clear
    theOs = 0
End If
On Error GoTo 0

然后,如果我们在 PC 上,我使用 提示,如果我们在 Mac 上,我使用 title ,像这样:

theQ1 = "This is my prompt"
theQ2 = ""
If theOs = 1 Then
    theQ2 = theQ1
    theQ1 = ""
End If
Set Rng1 = Application.InputBox(theQ1, theQ2, Type:=8)

对于 PC,它工作正常...对于 Mac,提示代替了标题,因此用户仍然可以理解请求的内容。一个重要的缺点是标题行在 space 中更受限制,我们不能使用换行符。

如果这仍然与您的需求相关,我前段时间遇到了类似的问题,我找到了一个令人满意的解决方案。我在这里概述了它: