Search code examples
excelvbacompiler-errorssave-as

vba 'Compiler error expected: =' on saveAs operation


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)

Solution

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

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