I think I am doing it all wrong

counihan3

Active Member
Joined
Mar 9, 2007
Messages
458
My goal is to run a macro in Book1 that will open Book2 and run a macro that will close and eventually delete Book1. My problem is that Book1's name will always be a variable. I thought (always a mistake) that I could just setup a reference to the Module to get the workbooks name which I made a public value. While that did allow me to "pass" then variable, I am not able to close Book1 now due to error of you cannot close a workbook where there is a reference. What do I do?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Where is the code located?

You can close the workbook it's in like this.
Code:
ThisWorbook.Close
 
Upvote 0
I tried that I am still getting the error about closing a workbook that is refenced. I think that I need to start over with my code. I just do not know how to move a variable from one workbook to another. In this case it is the workbooks name. So that the next macro will be able to delete it once it is done running.
 
Upvote 0

Forum statistics

Threads
1,203,316
Messages
6,054,702
Members
444,742
Latest member
jmartin9247

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