gpt4 book ai didi

vba - 循环后不考虑 wB.Save 和 wB.Close

转载 作者:行者123 更新时间:2023-12-02 06:03:30 26 4
gpt4 key购买 nike

我有一个包含多个工作簿的文件。我正在使用这个宏(如下)对此文件的每个工作簿进行一些更改。

Sub REPLACE1()
Dim y As Integer
Dim wB As Workbook
Set FileSystemObj = CreateObject("Scripting.FileSystemObject")
Set FolderObj = FileSystemObj.GetFolder("C:\MYLOCATION\")

For Each fileobj In FolderObj.Files
Set wB = Workbooks.Open(fileobj.Path)
With wB.Sheets("vlcs")
For y = 3 To .Cells(Rows.Count, 8).End(xlUp).Row
If .Cells(y, "A") = "" Then
.Cells(y, "A") = 0
End If
If .Cells(y, "O") = "" Then
.Cells(y, "O") = 0
End If
If Left(.Cells(y, "H").Value, 2) = "24" Then
.Cells(y, "H") = 2359
End If
Next y
End With
wB.Save
wB.Close '<---- Problems are from here
Next fileobj
End Sub

循环方面一切正常,但是 wB.Save 和 wB.Close 存在问题。对于每个循环的工作簿,我都会收到警报“您要保存更改吗”,这是不正常的,因为我保存并关闭了循环文件。此外,如果我单击"is",一切都会崩溃。我尝试将 DoEvents 放在 wB.Close 之后,但没有任何改变。感谢您的任何建议。

最佳答案

将其更改为wB.Close False,其中False表示不保存更改

关于vba - 循环后不考虑 wB.Save 和 wB.Close,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48828211/

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