vba 'Compiler error expected: =' on saveAs operation

Brian picture Brian · Feb 10, 2012 · Viewed 22.4k times · Source

The following line in my VBA code is generating the compile error 'Compiler error expected: =' implying that it expected an assignment. What am I doing wrong and how do I fix this?

I just want to save the file. Also, I want to overwrite the file which was previously a .xls or .xlsx file. Will this line do that?

Workbooks(theFile).SaveAs("Z:\test\vhb\" & newName, xlCSV)

Answer

Fionnuala picture Fionnuala · Feb 10, 2012

You do not use parentheses unless you are assigning to a variable.

Workbooks(theFile).SaveAs "Z:\test\vhb\" & newName, xlCSV