VBA不会关闭工作簿,并继续保存

时间:2017-06-30 12:39:11

标签: excel vba excel-vba

我对VBA很新,并尝试编写一个宏,当我打开它时会刷新,保存和关闭我的工作簿。它不会关闭工作簿,而是继续保存在较新版本中的所有时间。

Sub Main()

Dim sngStartTime, sngTotaltime As Date                                            
Dim LstUpdateRow As Integer                                                     
sngStartTime=Now                                                                

LstUpdateRow = Workbooks("Quick").Worksheets("settings").Range("c60000").End(xlUp).Row + 1               
sngTotaltime = Now - sngStartTime                                                 
Workbooks("Quick").Worksheets("Settings").Cells(LstUpdateRow, 3) = Now                                   
Workbooks("Quick").Worksheets("Settings").Cells(LstUpdateRow, 4) = sngStartTime                          
Workbooks("Quick").Worksheets("Settings").Cells(LstUpdateRow, 5) = sngTotaltime                          

End Sub

Sub RefreshData()

Application.Run "RefreshEntireWorkbook"

Application.Run "RefreshAllStaticData"

Application.OnTime Now() + TimeValue("00:00:05"), "Main"

End Sub

的ThisWorkbook:

Private Sub Workbook_Open()

Main
RefreshData

Workbooks("Quick").Close Savechanges:=true

End Sub

1 个答案:

答案 0 :(得分:2)

尝试推杆:

Workbooks("Quick.xlsm").Close Savechanges:=true

或者您对该特定工作簿的扩展名。我复制了工作簿(在某种程度上)并打开它,就像你自己一样。文件打开后,按照要求执行,保存和关闭。