Select Workbook with 2 Workbooks open

gottimd

Well-known Member
Joined
Jul 29, 2002
Messages
501
At one point in my macro, I will have a workbook called "x" (this workbook name will change often), and another workbook called "y" (name will remain constant).

At a a point in my macro, it only has "x" open, then saves it, and opens up "y". I then want it to close "x" but I can't figure out how to get it to close "x":
Code:
    ActiveWorkbook.Save      (workbook "x")
    Workbooks.Open Filename:="E:\Groups\Hyperion\Acterna\Corp\FY2004\" & Month & "\Entity Pack Template.xls"   (workbook "y")

    ActiveWorkbook.Close   (want this to be Workbook "x", but it closes "y")

When the last part of the code is executed, it closes "y" because that is the active workbook since it was just opened. How do I get it to select workbook "X" and close it. It would be easy if "X" had a constant name but it is always changing. Also, this will be part of a looped code, where "Y" is a template.
 

scuzz

Board Regular
Joined
Feb 1, 2004
Messages
57
im awfully confused...am i right in thinking that you have one workbook (A) and from that workbook you open another workbook (B), when B opens you want to close (A) and make B the active window?

Regards Scuzz
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

gottimd

Well-known Member
Joined
Jul 29, 2002
Messages
501
Nevermind......thank you both for your help.....I figured it out!!!!
 

Forum statistics

Threads
1,171,525
Messages
5,876,012
Members
433,166
Latest member
ExcelPowerUserWannabe

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
Top