vba '预期编译器错误:='保存为操作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9230381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:33:53  来源:igfitidea点击:

vba 'Compiler error expected: =' on saveAs operation

excelvbacompiler-errorssave-as

提问by Brian

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?

我的 VBA 代码中的以下行生成编译错误“预期编译器错误:=”,这意味着它需要赋值。我做错了什么,我该如何解决?

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?

我只想保存文件。另外,我想覆盖以前是 .xls 或 .xlsx 文件的文件。这条线会这样做吗?

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

回答by Fionnuala

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

除非为变量赋值,否则不要使用括号。

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