user8226217
user8226217

Reputation:

VBA won't close workbook, and keeps saving

I'm very new to VBA and tried to write a macro that will refresh, save and close my workbook when I open it. It won't close the workbook, but just keeps on saving all the time in a newer version.

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

Upvotes: 1

Views: 1170

Answers (1)

Busse
Busse

Reputation: 863

Try putting:

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

Or whatever your extension is for that particular workbook. I replicated the workbook (to an extent) and opened it as if you would yourself. The file opened, did what it was told to do, saved and closed.

Upvotes: 1

Related Questions