为什么在Excel for Mac中,我的InputBox使用VBA提示文本不出现? [英] Why does the prompt text not appear for my InputBox using VBA in Excel for Mac?
问题描述
这是我用于处理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屋!