Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with this snippet of VBA code?

Tags:

ms-word

vba

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

I'm getting "Compiler Error: Expected: =" error message.

like image 427
stanigator Avatar asked Apr 15 '12 02:04

stanigator


People also ask

How do I fix a VBA error in Excel?

To do this, click on 'Tools' and then click on 'Options'. In the options dialog box, make sure that the 'Auto Syntax Check' option is enabled. If the 'Auto Syntax Check' option is disabled, VBA will still highlight the line with the syntax error in red, but it will not show the error dialog box.

How do I bypass VBA error?

The “On Error Resume Next” is the error handler statement when we need to ignore the known error. If we want to ignore the error message only for a specific code set, close the On Error Resume Next statement by adding the “On Error GoTo 0” statement.

Is Microsoft getting rid of VBA?

Microsoft is finally planning to block Visual Basic for Applications (VBA) macros by default in a variety of Office apps. The change will apply to Office files that are downloaded from the internet and include macros, so Office users will no longer be able to enable certain content with a simple click of a button.

Why is VBA dreaded?

VBA has fallen out of favor because it hasn't kept up with the modern demands of a programming language. It has hardly changed since it was first introduced in 1993. Other languages have continues to evolve and newer languages have appeared to dominate the landscape.


1 Answers

It's because you can only call Subs either with Call or without parentheses in VBA. 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 =.)

like image 69
Ry- Avatar answered Oct 22 '22 19:10

Ry-