Reputation: 2861
I have a need to close the workbook i have a macro in and then reopen it after closing.
It is at the end of a process that makes various changes in some setting values and then saves a copy of the changed file. after saving the changed file, i then want to Close the current workbook (no save changes) and then open it so that way i can open it as it was before the changes occurred.
If there is a better way than Close then Open, by all means ill take advise.
This logic needs to happen in the Workbook and not anywhere outside of the Working Workbook, IE no Personal.xlsm or other personal method locations that will not travel with the workbook.
Upvotes: 3
Views: 2983
Reputation: 13122
Do something like this:
dim currentworkbookPath as string
'Store current workbook path to a string
currentworkbookPath = workbook.FullName
'Save the workbook somewhere else
Workbook.SaveAs 'I'll let you figure out the save as details yourself :P
'Open the old workbook.
Workbooks.Open currentworkbookPath
'Close the saved workbook.
Workbook.Close
Where Workbook is the actual workbook you're working with, you'll probably want to use ThisWorkbook
, but I didn't feel like assuming.
Incase you're not familiar here is the reference for Workbook.FullName
Upvotes: 5