Open another workbook while closing the active workbook

Karthikeyan Devan

Board Regular
Joined
May 5, 2009
Messages
114
Hi All,

My team is working on one tracker where at the end of the day they have to update it on the consolidate workbook. The problem here is people missing to update in the consolidate tracker.

So here what I need is that, when user close the active workbook then the consolidate workbook has to be opened automatically.

For example, If i am working on Karthik_tracker.xls and when i close this workbook another workbook should openend which i have saved it as consolidate_tracker.xls.

Any help on this would be very much appreciated!!!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hello,

Press Alt + F11
Press keystrokes Alt - I - M
Paste in the following to the module:

<font face=Courier New><br><SPAN style="color:#00007F">Public</SPAN> <SPAN style="color:#00007F">Function</SPAN> WorkbookOpen(WorkBookName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN><br><SPAN style="color:#007F00">' returns TRUE if the workbook is open</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    WorkbookOpen = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> WorkBookNotOpen<br>    <SPAN style="color:#00007F">If</SPAN> Len(Application.Workbooks(WorkBookName).Name) > 0 <SPAN style="color:#00007F">Then</SPAN><br>        WorkbookOpen = <SPAN style="color:#00007F">True</SPAN><br>        <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Function</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>WorkBookNotOpen:<br>Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN><br></FONT>

Now find ThisWorkBook from the tree at left
Double Click to bring up ThisWorkBook Code
Past in the following

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_BeforeClose(Cancel <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>)<br><br><SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> WorkbookOpen("consolidate_tracker.xls") <SPAN style="color:#00007F">Then</SPAN> Workbooks.Open ("C:\YOUR FULL FILE PATH\consolidate_tracker.xls")<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Your full file path will need to go where specified.

Now when you close the workbook with this code, the second workbook should open.
 
Upvote 0
just like repairman said.
He was much more detailed than what i was posting
 
Last edited:
Upvote 0
Wow!! Really perfect!! Thanks a lot...

A small help on this same macro. Before the provided macro run a Msgbox should display stating "Please update consolidate tracker".

I mean, when a user try to close the active workbook, a msgbox should display stating: "Please update consolidate workbook". Once user click on ok command button in msgbox, automatically the other workbook should open!!!

I am really satisfied with what you have provided but even the Msgbox get succeed it would be a really great help!!

Appreciate your help!!!
 
Upvote 0
This adds the msgbox:

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_BeforeClose(Cancel <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>)<br><br>MsgBox "Please update consolidate workbook", vbOKOnly, "Update Consolidate Tracker."<br><br><SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> WorkbookOpen("consolidate_tracker.xls") <SPAN style="color:#00007F">Then</SPAN> Workbooks.Open ("C:\YOUR FULL FILE PATH\consolidate_tracker.xls")<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,214,797
Messages
6,121,629
Members
449,041
Latest member
Postman24

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