Excel VBA Macro to Close a Workbook without Saving and Reopen

Excel VBA Macro to Close a Workbook without Saving and Reopen

I wrote this macro and use it all the time when writing new macros. Feel free to use.

 

Sub ClosewithoutsaveAndReopen()
‘Defines Variables
Dim nameOfCurrentWorkbook As Variant
Dim nameOfCurrentWorkbookPath As Variant

‘Finds the name of the current workbook
nameOfCurrentWorkbook = ActiveWorkbook.Name

‘finds the current path of hte workbook
nameOfCurrentWorkbookPath = ActiveWorkbook.Path

ActiveWorkbook.Close False
‘Reopens the same worbook you just closed
‘If in the same workbook
Workbooks.Open (nameOfCurrentWorkbookPath & “\” & nameOfCurrentWorkbook)
‘if in a specific workbook
‘Workbooks.Open (“C:\Users\VMWindows7\Desktop\SAS CARB 2012_44.xlsx”)
End Sub

 

 

Excel VBA Macro to Close a Workbook without Saving and Reopen

Leave a Reply

Your email address will not be published. Required fields are marked *