为什么在Excel for Mac中,我的InputBox使用VBA提示文本不出现? [英] Why does the prompt text not appear for my InputBox using VBA in Excel for Mac?

查看:192
本文介绍了为什么在Excel for Mac中,我的InputBox使用VBA提示文本不出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在建立一个使用Excel跟踪学生成绩的系统。我已经在Windows下编码了,一切都正常,但是当我在Mac版本的Excel(最新版​​本,15.24,我相信)测试它时,InputBoxes只显示输入数据的标题和文本框;提示文本未显示。
这是我用于处理InputBoxes的代码示例:

  On Error Resume Next 
assessmentName = Application.InputBox(请输入新评估的名称,输入评估名称)
如果assessmentName =False则
Exit Sub
End If
Err.Clear

在这种情况下,所有显示的都是输入评估名称以及用户键入名称的文本框。
Mac版本的Excel处理VBA代码的方式有差异,这将导致这种情况发生吗?问题是我的代码编码不好,加上Excel似乎在Mac上的VBA支持较弱?



更新:我现在已经在代码中标注了这些参数:

  On Error Resume Next 
assessmentName = Application。 InputBox(_
提示:=请输入新评估的名称,_
标题:=输入评估名称)
如果assessmentName =False则
退出Sub
结束如果
Err.Clear

不幸的是,提示是当我在Mac版本的Excel上运行宏时,仍然缺少。



SECOND UPDATE:我找到了解决方案并将其发布在

解决方案

我找到了答案,并将其发布在这里,希望帮助其他谁拥有同样的问题。当我阅读此页面我发现以下评论:


微软好像很迷惑,所以你也可以访问InputBox方法是Application对象的一种方法。


所以原来我使用的是Application.InputBox,当我应该使用简单的InputBox。



以下代码可以工作,即它显示提示以及输入框和标题:

  On Error Resume Next 
assessmentName = InputBox(_
提示:=请输入新评估的名称,_
标题:=输入评估名称)
如果assessmentName =False然后
退出子
结束如果
Err.Clear


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.

解决方案

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

这篇关于为什么在Excel for Mac中,我的InputBox使用VBA提示文本不出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆