gpt4 book ai didi

vba - 关闭所有工作簿但激活一个而不断开链接?

转载 作者:行者123 更新时间:2023-12-04 21:58:34 25 4
gpt4 key购买 nike

我想关闭所有工作簿,但不破坏链接的事件簿。

Sub dateUpdate()

Dim WB As Workbook
Dim TestWkbk As Workbook
Dim obj As Object
Range("C1").Select

Application.ScreenUpdating = False
Workbooks.Open Filename:=ActiveWorkbook.Path & "\receiving.xlsx", ReadOnly:=True
ActiveWindow.Visible = False
Workbooks.Open Filename:=ActiveWorkbook.Path & "\packing.xlsx", ReadOnly:=True
ActiveWindow.Visible = False
Workbooks.Open Filename:=ActiveWorkbook.Path & "\shipping.xlsx", ReadOnly:=True
ActiveWindow.Visible = False
Workbooks.Open Filename:=ActiveWorkbook.Path & "\hoist.xlsx", ReadOnly:=True
ActiveWindow.Visible = False
ThisWorkbook.Activate
'Application.ScreenUpdating = True



If Val(Application.Version) >= 12 Then
Set TestWkbk = Nothing
On Error Resume Next
Set TestWkbk = Workbooks("WinDatePicker.xlam")
On Error GoTo 0
If TestWkbk Is Nothing Then
MsgBox "Sorry the Date Picker add-in is not open."
Else
Application.Run "'" & TestWkbk.Name & "'!OpenDatePicker", obj
End If
End If


For Each WB In Workbooks
If WB.Name <> ThisWorkbook.Name Then
WB.Close savechanges:=False
End If
Next WB


End Sub

如果我选择一个新的日期,那么我会收到引用错误,因为这些书已经关闭。有什么办法吗?

最佳答案

下面的代码将关闭除事件工作簿之外的所有工作簿

Dim wb As Workbook
For Each wb In Application.Workbooks
If Not (wb Is Application.ActiveWorkbook) Then
wb.Close
End If
Next

关于vba - 关闭所有工作簿但激活一个而不断开链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39235541/

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