4

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)
Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
Brian
  • 1,128
  • 7
  • 18
  • 27

1 Answers1

15

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

Workbooks(theFile).SaveAs "Z:\test\vhb\" & newName, xlCSV
Fionnuala
  • 90,370
  • 7
  • 114
  • 152
  • Thanks, it didn't make sense to me to assign my saving. – Brian Feb 10 '12 at 16:07
  • 4
    @Brian if you really want to use the parentheses you can use `Call`: `Call Workbooks(theFile).SaveAs("Z:\test\vhb\" & newName, xlCSV)` -- but I have to say I really don't like this approach, because it adds nothing other than verbosity. – phoog Feb 10 '12 at 18:20