简体   繁体   English

这段 VBA 代码有什么问题?

[英]What's wrong with this snippet of VBA code?

 If TextBox1.Text = "" Or TextBox1.Text = "False" Then
        msgbox("Filename invalid. Try again.",vbOKOnly)

I'm getting "Compiler Error: Expected: =" error message.我收到“编译器错误:预期:=”错误消息。

It's because you can only call Sub s either with Call or without parentheses in VBA.这是因为您只能在 VBA 中使用Call或不带括号来调用Sub So change it to:所以改成:

MsgBox "Filename invalid. Try again.", vbOKOnly

Or, if you like this style better:或者,如果您更喜欢这种风格:

Call MsgBox("Filename invalid. Try again.", vbOKOnly)

(And the reason you get the error is because it expects you to assign the result to a variable, hence it expects an = .) (并且您收到错误的原因是因为它希望您将结果分配给一个变量,因此它需要一个= 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM