Reputation: 53
I run the macro from another workbook, as i generate daily reports, i already save them but i want to close them after saving them, i tried with ThisWorkbook.Close and ThisActiveWorkbook.Close it just stops the loop from the macro and it doesn't close the workbook.
Here is my code:
Dim IntialName As String
Dim sFileSaveName As Variant
IntialName = "Sample"
sFileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitialName, filefilter:="Workbook(*.xlsx), *.xlsx")
If sFileSaveName <> False Then
ActiveWorkbook.SaveAs sFileSaveName, FileFormat:=51
End If
End With
xFileName = Dir
Loop
End If
Upvotes: 0
Views: 41
Reputation: 49998
ThisWorkbook
is the workbook with the code in it, not the one you want to close.
ThisActiveWorkbook
is nothing at all.
Use:
ActiveWorkbook.Close SaveChanges:=False
Upvotes: 1