关闭所有工作簿但活动一个没有断开链接?

时间:2016-08-30 19:22:14

标签: vba excel-vba excel

我希望关闭所有工作簿,但不要断开链接。

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

如果我选择新的日期,那么我会收到参考错误,因为这些图书已经关闭。有什么方法吗?

2 个答案:

答案 0 :(得分:2)

以下代码将关闭除活动工作簿之外的所有工作簿

$state.go('^.template2');

答案 1 :(得分:1)

关闭除活动工作簿之外的所有内容

CODE1$INAME$ISURNAME$ICODE2$ICODE3$ICODE4