检查SaveAs是否成功VBA [英] Checking to see if SaveAs was successful VBA
问题描述
Sub saveBookAs( )
wb.SaveAs fileName = =newFile
End Sub
您不需要声明来检查工作簿是否已保存:)如果另存为
进程失败那么该行将自动错误出现))
如果你想检查一个文件是否存在,可以随时使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!