模拟 Excel 上的取消按钮“保存更改";弹出 [英] Simulate button Cancel on Excel "Save changes" pop up

查看:75
本文介绍了模拟 Excel 上的取消按钮“保存更改";弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VBA 脚本自动执行 SAP 事务.事务将一些数据提取到 Excel 模板,显示生成的 Excel 文件,并出于某种原因尝试退出它,显示保存更改"弹出窗口,这是事务结束的地方.

I'm trying to automate a SAP transaction using a VBA script. The transaction extracts some data to an Excel template, displays the resulting Excel file and for some reason tries to exit it which shows the "save changes" pop up window, this is where the transaction ends.

我希望我的 VBA 代码在保存更改弹出窗口中单击取消".

I want my VBA code to click "cancel" on the save changes pop up window.

我希望我的 VBA 在不同的项目上执行此事务并将生成的 .xls 文件保存到特定位置,问题是此弹出窗口会停止代码,我必须手动单击它.

I want my VBA execute this transaction on different items and save the resulting .xls files to a specific location, the problem is this pop up window stops the code and I have to click it manually.

禁用弹出窗口无济于事,因为文件将退出而不保存并丢失.我无权更改 SAP 代码,因此我唯一的选择是通过 VBA 运行脚本.

Disabling the Pop up will not help as the file will exit without saving and will be lost. I don't have authorization to change the SAP code so my only option is to run a script through VBA.

推荐答案

要强制工作簿保存更改,请在该工作簿的 Visual Basic 模块中键入以下代码:

To force a workbook to save changes, type the following code in a Visual Basic module of that workbook:

Sub Auto_Close()

    If ThisWorkbook.Saved = False Then
        ThisWorkbook.Save 
    End If

End Sub

此子过程检查文件 Saved 属性是否已设置为 False.如果是,则工作簿自上次保存以来已更改,并且这些更改将被保存.

This subprocedure checks to see if the file Saved property has been set to False. If so, the workbook has been changed since the last save, and those changes are saved.

来源:https://support.microsoft.com/en-us/office/-how-to-save-changes-prompt-when-you-close-a-workbook-in-excel-189a​​257e-ec1b-40f7-9195-56d82e673071?ui=en-us&rs=en-us&ad=us

这篇关于模拟 Excel 上的取消按钮“保存更改";弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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