解决方案
您不需要声明来检查工作簿是否已保存:)如果另存为进程失败那么该行将自动错误出现))
如果你想检查一个文件是否存在,可以随时使用 DIR 函数。 DIR 返回一个字符串,表示与指定的模式或文件属性匹配的文件,目录或文件夹的名称,或者驱动器的卷标。
语法
Dir [(pathname [,attributes])]
查看VBA帮助了解更多详情。
EDIT
另一个提示。
如果你不想让你的代码中断,那么你也可以使用正确的错误处理。 p>
例如
Sub Sample() On Error GoTo Whoa ActiveWorkbook.Save SomeFilePathAndName 退出子哇: MsgBox Err.Description End Sub
What kind of statement do I need to check whether or not a SaveAs operation was successful in vba?
Sub saveBookAs() wb.SaveAs fileName:="newFile" End Sub解决方案
You don't need a statement to check if the workbook was saved or not :) If the Save As process fails then that line will error out automatically :)
Having said that if you want to check if a file exists or not you can always use the DIR function. DIR Returns a String representing the name of a file, directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.
Syntax
Dir[(pathname[, attributes])]
Check VBA help for more details.
EDIT
Another tip.
If you don't want your code to break, then you can also use proper Error Handling.
For example
Sub Sample() On Error GoTo Whoa ActiveWorkbook.Save SomeFilePathAndName Exit Sub Whoa: MsgBox Err.Description End Sub
更多推荐
检查SaveAs是否成功VBA
发布评论