VBA工作簿Savechanges = False仍在运行宏时保存和关闭工作簿 [英] VBA Workbook Savechanges = False still saving and closing workbook when running Macro

查看:1844
本文介绍了VBA工作簿Savechanges = False仍在运行宏时保存和关闭工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主工作簿,该工作簿从其他工作簿工作表中提取数据,然后关闭修改后的工作簿,并取消保存选项.

I have a main workbook that extracts data from other workbook sheets, then closes the modified workbook suppressing the save option.

other_wb.Close Savechanges = False

other_wb.Close Savechanges = False

但是,当在调试模式下运行宏或单步执行此函数调用时,它仍会保存文件.是否有另一种无需保存即可关闭的方法?这种行为有什么解释吗?

However when running the macro or stepping through this function call in DEBUG mode it still saves the file. Is there an alternative way to close without saving? Is there any explanation for this behavior?

如果需要,我可以提供更多信息.

I can provide more info if needed.

推荐答案

Savechanges是未定义的变量.因此它是Empty; Empty是虚假的,因此表达式Savechanges = False的计算结果为True,因此调用变为other_wb.Close True,这将保存文件.

Savechanges is an undefined variable. It is therefore Empty; Empty is falsy, so the expression Savechanges = False evaluates to True, so the call becomes other_wb.Close True, which saves the file.

您缺少冒号:

other_wb.Close Savechanges:= False

Option Explicit放在所有代码模块的顶部,这样就永远不必处理此类问题.

Put Option Explicit on top of all your code modules to never have to deal with this kind of issues.

这篇关于VBA工作簿Savechanges = False仍在运行宏时保存和关闭工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆