Opening new workbook

D

Derek

I have a piece of code that someone else has written.
There is a line of code that opens another workbook
(wkBk2):

Workbooks.Open FileName:=(wkBk2)

The program does open the new workbook. The next line of
code causes a crash (Run-Time error 9):

Sheets("April").Activate

The problem arises because the "April" worksheet is NOT in
the ActiveWorkbook. It is, however, in the newly opened
workbook (wkBk2). I would expect the newly opened wkBk2
to be the active workbook (since it was just opened), but
it is not. Apparently, this program has been up and
running for over a year. Now, however, this piece of code
is causing it to crash. I would appreciate some help in
understanding why this could all of a sudden stop
running. TIA...
 
B

Bob Flanagan

Derek, the workbook wkBk2 was saved while it was minimized. This prevents
it from being the active workbook when opened. To make it the
activeworkbook, use the following line:

Workbooks(wkBk2).Activate

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 
D

Derek

Thank you. You were correct...It was minimized.
-----Original Message-----
Derek, the workbook wkBk2 was saved while it was minimized. This prevents
it from being the active workbook when opened. To make it the
activeworkbook, use the following line:

Workbooks(wkBk2).Activate

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel




.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top