VBA Workbook Savechanges = False still saving and

2019-09-05 05:05发布

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

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.

1条回答
The star\"
2楼-- · 2019-09-05 05:44

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.

You are missing the colon:

other_wb.Close Savechanges:= False

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

查看更多
登录 后发表回答