检查SaveAs是否成功VBA

编程入门 行业动态 更新时间:2024-10-27 14:18:00
本文介绍了检查SaveAs是否成功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

本文发布于:2023-11-07 15:03:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SaveAs   VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!