gpt4 book ai didi

vba - 用于恢复保存后更改的宏

转载 作者:行者123 更新时间:2023-12-03 01:47:03 25 4
gpt4 key购买 nike

我在网上发现了一个旧脚本,可以关闭文档而不保存更改,然后重新打开文档:

Sub RevertFile()
wkname = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
ActiveWorkbook.Close Savechanges:=False
Workbooks.Open Filename:=wkname
End Sub

我想要这个,因为你无法“撤消”由运行宏引起的更改。但是,它似乎不适用于 MS Office v1609。首先,文档关闭后不会重新打开。其次,当我不希望保存修改时,它们会被保存。我怎样才能重写这个脚本以使其正常工作?谢谢。

[编辑]

这是我正在使用的另一个子例程。

Sub FixPlatforms()
'PURPOSE: Find & Replace a list of text/values throughout entire workbook
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

Dim sht As Worksheet
Dim platList As Variant
Dim x As Long

platList = Array _
( _
"PS4", "PlayStation 4", _
"PS3", "PlayStation 3", _
"PS2", "PlayStation 2", _
"PSV", "PlayStation Vita", _
"PSP", "PlayStation Portable", _
"WIN", "Microsoft Windows", _
"SNES", "Super Nintendo Entertainment System" _
)


'Loop through each item in Array lists
For x = 1 To UBound(platList) Step 2
'Loop through each worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
sht.Cells.Replace What:=platList(x), Replacement:=platList(x - 1), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht

Next x

End Sub

是不是有什么问题?

最佳答案

无论如何,您都不必关闭工作簿。尝试打开已打开的工作簿会产生以下结果。

enter image description here

添加 application.displayalerts = false 应该足以避免该确认。

Option Explicit

Sub RevertFile()
Dim wkname As String
wkname = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
Application.DisplayAlerts = False
Workbooks.Open Filename:=wkname
Application.DisplayAlerts = True
End Sub

关于vba - 用于恢复保存后更改的宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44244065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com