close workbook and reopen it

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,104
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi all

Is there a way of making something that closes the workbook down and re-opens it again without saving the previous work.
I have some code that runs, saves various things and creates reports etc.
But when it has finished and i want to paste new info into it, i have to close it and then re-open it, would be great to make it happen by itself ready for the next lot of data.
Thanks

dave
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
ok all

answered my own question.
this may help someone else?

Code:
Sub CloseMe() 
    Application.OnTime Now + TimeValue("00:00:10"), "OpenMe" 
    ThisWorkbook.Close False 
End Sub 

Sub OpenMe() 
    MsgBox "I'm Back!" 
End Sub

Dave
 
Upvote 0
Hi Dave
To answer your question directly....No.
However, you would only be able to close and re-open a workbook from another workbook or app that remains open.
I guess the question is why do you need to close and re-open to paste new data into it ?
 
Upvote 0
Sorry Dave, unless I'm not understanding you correctly....the code you posted won't close the workbook.....and then re-open it !
 
Upvote 0
It actually will, Michael. That's why you need to deliberately unschedule any scheduled macros before you close a workbook.
 
Last edited:
Upvote 0
It actually will, Michael. That's why you need to deliberately unschedule any scheduled macros before you close a workbook.

Well ain't that something?! I would have expected the "I can't find xxx macro" msg.
 
Upvote 0
Bear in mind that the workbook will only reopen if the application is still running. I have come accross a similar scenario where I needed to reopen a workbook via code and I used a VBScript created upon closing on the fly to re-launch the workbook and the application if required.
 
Upvote 0
Thanks GTO....I thought exactly that !!!
****, my tag line still rings true .....LOL !
 
Upvote 0
Hi guys

all I can say is it works just fine, i am using it now.
all my macros finish running, creates my reports, closes and then re-opens?
Ready for the new data

Dave
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top